First, the common parameters
grammar |
effect |
---|---|
window= tk.TK() |
Creating a window |
window['height'] = 300 |
Set high |
window['width'] = 500 |
Set Width |
window.title ( 'cube station') |
Set Title |
window['bg'] = '#0099ff' |
Set the background color |
window.geometry("500x300+120+100") |
Setting the window size, +120 means the distance from the screen to the left of the window |
window.option_add('*Font', 'Fira 10') |
To set global font |
window.resizable(width=False,height=True) | root.resizable(0,1) |
Barred window resize |
window.minsize(300,600) |
Adjustable minimum window |
window.maxsize(600,1200) |
Adjustable maximum value of the window |
window.attributes("-toolwindow", 1) |
Toolbar Style |
window.attributes("-topmost", -1) |
Top window |
window.state("zoomed") |
Maximize the window |
window.iconify() |
Window is minimized |
window.deiconify() |
Restore window |
window.attributes("-alpha",1) |
Window transparency, transparency from 0-1,1 is opaque, 0 is fully transparent |
window.destroy() |
close the window |
window.iconbitmap("./image/icon.ico") |
Settings window icon |
screenWidth = window.winfo_screenwidth() |
Gets the screen width and height |
window.protocol("WM_DELETE_WINDOW", call) |
When the window is closed, the function call performed |
window.mainloop () |
The main window loop update |
Second, the sample code
TK Tkinter AS Import # create a form window tk.Tk = () DEF Call (): Global window window.destroy () DEF main (): Global window # Set the size of the main form winWidth = 600 winHeight = 400 # acquired screen resolution rate screenWidth = window.winfo_screenwidth () screenHeight window.winfo_screenheight = () # calculating a main window on the screen coordinates X = int ((screenWidth - winWidth) / 2) Y = int ((screenHeight - winHeight) / 2) # set main window title window.title ( "main form parameter Description") # main window size window.geometry ( "% S% + SX +% S% S"% (winWidth, winHeight, X, Y)) # setting window width and height fixed window.resizable (0,0) # Set the window icon window.iconbitmap ( "./ Image / icon.ico") # top style setting window window.attributes ( "- the toolwindow", 0) # Set window transparency window.attributes ( "- Alpha",. 1) # get the current window state Print (window.state ()) window.protocol ( "WM_DELETE_WINDOW", Call) # loop update window.mainloop () IF __name__ == "__main__": main ()