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