Tkinter study Three

Source: Internet
Author: User

Configure component appearance (configuring Widget appearance)

 fromTkinterImport*Root=Tk () Labelfont= (' Times', 20,'Bold')#family, size, style font family, sizes, typeWidget = Label (root, text='Hello config world') widget.config (BG='Black', fg='Yellow')#Yellow text on black Label displays yellow text on a dark labelWidget.config (Font=labelfont)#use a larger font with larger fontsWidget.config (height=3, width=20)#initial size:lines,chars initialization size, line spacing, character spacingWidget.pack (Expand=yes, fill=BOTH) Root.mainloop ()

Small knowledge:

Borders and Emboss:

A "bd=n" component option can be used to set the border width, while the relief=s option can develop a type of border, S can be flat (flat), SUNKEN (Sunken), Groove (Groove), SOLID (bold), or Ridge (ridged)

Cursor:

The cursor option can change the appearance of the mouse when the mouse passes through the component, for example: The state=disabled option typically disables the component function on the screen (when disabled, the component turns gray), and the normal state does not disable the component function. Some of the main pieces also support the ReadOnly (read-only) property, and the components that are set to that property display correctly, but cannot be modified.

Stay white:

Additional space can be added around many of the main items, such as buttons, labels, and text, and can be implemented with the Padx=n and pady=n options.

Example:

 fromTkinterImport*Widgets= Button (text='Spam', padx=10, pady=10) Widget.pack (PADX=20, pady=20) widget.config (cursor='Gumby') Widget.config (BD=8, relief=raised) widget.config (BG='Dark green', fg=' White') widget.config (font=('Helvetica', 20,'Underline Italic') ) Mainloop ()

Top-level window, Tkinter can create any number of separate windows by toplevel the main part.

ImportSYS fromTkinterImporttoplevel, Button, Labelwin1= TopLevel ()#Independent WindowsWin2 = TopLevel ()#But part of same processButton (Win1, text='Spam', command=sys.exit). Pack () Button (win2, Text='SPAM', command=sys.exit). Pack () Label (text='popups'). Pack ()#On default Tk () root windowWin1.mainloop ()
Label (text='popups'# on default Tk () rootwindow# defaults to Windows root = tk () Label (root, text='popups'# on explicit TK ( ) Rootwindowroot.mainloop ()# show root Windows
Import Tkinter  from Import  #  Independent root windowswin2 = Tk () Button (win1, text='Spam  ', command=Win1.destroy). Pack () Button (win2, text='SPAM' , command=Win2.destroy). Pack () Win1.mainloop ()

Tkinter study Three

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.