Python GUI programming (Tkinter Library) (iii)

Source: Internet
Author: User
Tags pack
messages (message)

Message controls provide a way to display multiple lines of text, and you can set the font and background colors
Example:

From tkinter Import *
root=tk ()
root.title ("top") message
(root,text= ' Your can record your wonderful-thing, Can record your wonderful thing ', \
        bg= ' Blue ', fg= ' ivory ', Relief=groove). Pack (padx=10,pady=10)
Root.mainloop ()

Results:
list (ListBox)

A list box component is a list of options from which a user can select an option
Example:

From tkinter Import *
root=tk ()
root.title ()
l=listbox (root,width=15)
l.pack () for
item in [' Apple ', ' orange ', ' peach ', ' banana ', ' melon ':
    l.insert (End,item)
Root.mainloop ()

Results:
scroll bar (Scrollbar)

The scrollbar component can be added to any one component, and some components will automatically add scrollbars when the interface is not displayed, but you can use the ScrollBar component to control the scroll bar
Example:

From tkinter Import *
root=tk ()
root.title (' top ')
L=listbox (root,height=6,width=15)
scroll= Scrollbar (Root,command=l.yview)
l.configure (yscrollcommand=scroll.set)
l.pack (side=left)
Scroll.pack (side=right,fill=y) for
item in range:
    l.insert (End,item)
Root.mainloop ()

Results:
message box (MessageBox)

The message window is used to pop-up the alert box like a user warning, or to let the user choose what to do next, the message box includes many types, long with info, warning, error, Yesno, Okcancel, and so on, including different icons, buttons, and pop-up prompts.
Example:

Import Tkinter as TK import Tkmessagebox as MsgBox def btn1_clicked (): Msgbox.showinfo ("info", "Showinfo test.")
Def btn2_clicked (): msgbox.showwarning ("Warning", "showwarning test.")
Def btn3_clicked (): Msgbox.showerror ("Error", "ShowError test.")
Def btn4_clicked (): Msgbox.askquestion ("question", "askquestion test.")
Def btn5_clicked (): Msgbox.askyesno ("Yesno", "AskYesNo test.")
Def btn6_clicked (): Msgbox.askokcancel ("Okcancel", "Askcancel test.")
Def btn7_clicked (): Msgbox.askretrycancel ("Retry", "Askretrycancel test.") Root=tk. Tk () root.title ("Msgbox test") btn1=tk. Button (root,text= "Showinfo", command=btn1_clicked) Btn1.pack (FILL=TK. X) btn2=tk. Button (root,text= "showwarning", command=btn2_clicked) Btn2.pack (FILL=TK. X) btn3=tk. Button (root,text= "ShowError", command=btn3_clicked) Btn3.pack (FILL=TK. X) btn4=tk. Button (root,text= "Showaskquestion", command=btn4_clicked) Btn4.pack (FILL=TK. X) btn5=tk. Button (root,text= "AskYesNo", command=btn5_clicked) Btn5.pack (FILL=TK. X) btn6=tk. Button (root,text= "Showokcancel", command=btn6_clicked) Btn6.pack (FILL=TK. X) btn7=tk. Button (root,text= "Showretrycancel", command=btn7_clicked) Btn7.pack (FILL=TK.
 X) Root.mainloop ()

Result:

Click Related action:

Continue:

Continue:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.