怎么调整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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值