如何仅指定地点而不指定tkinter窗口的大小?

问题描述 投票:1回答:1

现在我正在使用这样的东西放置我的窗口:

def center_win(self):
    screen_width = self.master.winfo_screenwidth()
    screen_height = self.master.winfo_screenheight()
    win_width = int(screen_width / 2)
    win_height = int(screen_height / 3)   
    x_pos = int((screen_width - win_width) / 2 )
    y_pos = int((screen_height - win_height) / 2)
    self.master.geometry('{}x{}+{}+{}'.format(win_width, win_height,
                                              x_pos, y_pos))

我想给窗口的X和Y坐标,而不是尺寸。大小由pack()自动确定,这很好。有没有办法只将x_pos和y_pos参数传递给.geometry方法?

python tkinter
1个回答
4
投票

当然只设置"+{}+{}"部分:

root.geometry("+{}+{}".format(256, 512))
#or more generally
#widget.winfo_toplevel().geometry("+{}+{}".format(256, 512))
© www.soinside.com 2019 - 2024. All rights reserved.