How to set the size of a window?
如何调整
1
2 3 4 5 6 7 8 |
try: # In order to be able to import tkinter for import tkinter as tk # either in python 2 or in python 3 except ImportError: import Tkinter as tk root = tk.Tk() |
如何调整
1
2 3 4 5 6 7 8 9 |
try: # In order to be able to import tkinter for import tkinter as tk # either in python 2 or in python 3 except ImportError: import Tkinter as tk root = tk.Tk() |
可以使用
1
2 |
# identical to root.geometry(‘256×512’)
root.geometry(‘{}x{}’.format(256, 512)) |
或:
1
2 |
# identical to window.geometry(‘512×256’)
window.geometry(‘{}x{}’.format(512, 256)) |
另外使用几何方法也可以确定窗口的左上角:
1
|
window.geometry(‘+{}+{}’.format(16, 32))
|
或者两者兼而有之:
1
2 |
#identical to window.geometry(‘512×256+16+32’)
window.geometry(‘{}x{}+{}+{}’.format(512, 256, 16, 32)) |
更一般地说,可以使用
1
|
widget.winfo_toplevel().geometry(‘{}x{}+{}+{}’.format(512, 256, 16, 32))
|
例子
这是一个通过子部件的引用设置窗口大小和位置坐标的示例:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3 except ImportError: import Tkinter as tk def on_button_press(widget):
if __name__ == ‘__main__’: |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/267962.html