Tkinter.TK

Tkinter.TK


How the author in front of Hello, Tkinter this simple demonstration about the most basic Tkinter program you want to write. Here about how to record further through Tkinter.TK class to set and control our window.

Before setting the Tkinter package import remember first come in, come in after the import declaration, we can operate the set.

from Tkinter import *
form = Tk()

To set the title of the window can be called by TK.title method, into a string to be displayed in the window title.

form.title("Tkinter.TK Demo")

Small icon to be set before the window title, a small icon may be called by the file location TK.iconbitmap method, into the front window title to be displayed.

form.iconbitmap('Icon.ico')

To set the background color of the window can be called by TK.configure way into the window's background color.

form.configure(background='black')
form.configure(background='#888888')

Do you want to set the zoom window can be called by TK.resizable method. Into the first parameter is used to specify whether the size of the width adjustment for zooming, the second is used to specify whether the size of the height adjustment for zooming.

form.resizable(False, False)

To set the size of the window start position, you can be called by TK.geometry method, into a specific format string (width x length + left + right shift displacement). Like "300x200 + 10 + 10" is to establish the size of the window (10, 10) in this position. If necessary side can specify only the position of the window size, or the window, such as "300x200" and "+ 10 + 10."

form.geometry("300x200+10+10")

To set the minimum window size scaling, you can be called by TK.minsize method, the window into the minimum acceptable width and height.

form.minsize(300, 200)

To set the maximum zoom window size, the method can invoke TK.maxsize, into the maximum acceptable window width and height.

form.maxsize(600, 400)

To become a window ToolWindow Style, you can call TK.attributes ( "- toolwindow", 1).

form.attributes("-toolwindow", 1) 

To top window to window, you can call TK.attributes ( "- topmost", 1).

form.attributes("-topmost", 1) 

To maximize startup, you can call TK.state ( "zoomed").

form.state("zoomed")

To minimize TK.iconify can call the method.

form.iconify()

To restore a minimized can call TK.deiconify method.

form.deiconify()

Finally, as a practical matter complete usage examples:

from Tkinter import *

form = Tk()

form.title("Tkinter.TK Demo")
form.geometry("300x200+10+10")
form.iconbitmap('Icon.ico')
#form.resizable(False, False)
form.minsize(300, 200)
form.maxsize(600, 400)
#form.attributes("-toolwindow", 1) 
form.attributes("-topmost", 1) 
#form.state("zoomed")
#form.iconify()
#form.deiconify()
form.configure(background='black')

form.mainloop()

Up and running will be like this:

image

Link

  • Toplevel Window Methods

Original: Big Box  Tkinter.TK


Guess you like

Origin www.cnblogs.com/chinatrump/p/11467094.html