怎么调整python窗口大小_如何设置窗口大小?

可以使用^{}方法设置窗口的大小(可以是Tk实例或Toplevel实例):

^{1}$

或者:

^{pr2}$

另外,使用几何方法还可以确定窗口的左上角:window.geometry('+{}+{}'.format(16, 32))

或者两者兼而有之:#identical to window.geometry('512x256+16+32')

window.geometry('{}x{}+{}+{}'.format(512, 256, 16, 32))

{a2的子窗口通常可以从一个更容易设置的窗口中使用}:widget.winfo_toplevel().geometry('{}x{}+{}+{}'.format(512, 256, 16, 32))

示例

下面是一个通过子控件的引用设置窗口的大小和位置坐标的示例: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):

width = 512

height = 256

x = 16

y = 32

widget.winfo_toplevel().geometry('{}x{}+{}+{}'.format(width, height, x, y))

if __name__ == '__main__':

root = tk.Tk()

window = tk.Toplevel(root)

button = tk.Button(window, text="Resize & Place")

#the line below is related to calling a method when a button is pressed

button['command'] = lambda w=button: on_button_press(w)

button.pack()

tk.mainloop()

你可能感兴趣的:(怎么调整python窗口大小)