【发布时间】:2021-02-19 23:36:14
【问题描述】:
当显示用户变量时,我在 tkinter 中调整窗口大小时遇到问题。由于程序采用团队的名称并稍后在程序中显示它,因此为显示窗口设置大小将不起作用,因为它需要自适应。我有让窗口居中的代码,但是有没有办法自动设置窗口的大小?
当前外观:
team_2 = t2_entry.get()
top_2.withdraw()
confirm_screen = Toplevel(master)
w = 160 + len(team_2) + len(team_1)
h = 50
ws = confirm_screen.winfo_screenwidth()
hs = confirm_screen.winfo_screenheight()
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
confirm_screen.geometry('%dx%d+%d+%d' % (w, h, x, y))
t1_name = Label(confirm_screen, text = "Team 1: " + team_1).grid(row = 1, column = 1)
t2_name = Label(confirm_screen, text="Team 2: " + team_2).grid(row = 1, column = 2)
confirm_button = Button(confirm_screen, text = "Submit", width = 10, command = team_name_1).grid(row = 4, column = 1)
redo = Button(confirm_screen, text="Redo", width=10, command= lambda: [start_team1(), clear()]).grid(row=4, column=2)
尝试 1:
team_2 = t2_entry.get()
top_2.withdraw()
confirm_screen = Toplevel(master)
w = 160 + len(team_2) + len(team_1)
h = 50
ws = confirm_screen.winfo_screenwidth()
hs = confirm_screen.winfo_screenheight()
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
confirm_screen.geometry('%dx%d+%d+%d' % (w, h, x, y))
t1_name = Label(confirm_screen, text = "Team 1: " + team_1).grid(row = 1, column = 1)
t2_name = Label(confirm_screen, text="Team 2: " + team_2).grid(row = 1, column = 2)
confirm_button = Button(confirm_screen, text = "Submit", width = 10, command = team_name_1).grid(row = 4, column = 1)
redo = Button(confirm_screen, text="Redo", width=10, command= lambda: [start_team1(), clear()]).grid(row=4, column=2)
尝试 2:
team_2 = t2_entry.get()
top_2.withdraw()
confirm_screen = Toplevel(master)
w = confirm_screen.winfo_width
h = confirm_screen.winfo_height
ws = confirm_screen.winfo_screenwidth()
hs = confirm_screen.winfo_screenheight()
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
confirm_screen.geometry('%dx%d+%d+%d' % (w, h, x, y))
t1_name = Label(confirm_screen, text = "Team 1: " + team_1).grid(row = 1, column = 1)
t2_name = Label(confirm_screen, text="Team 2: " + team_2).grid(row = 1, column = 2)
confirm_button = Button(confirm_screen, text = "Submit", width = 10, command = team_name_1).grid(row = 4, column = 1)
redo = Button(confirm_screen, text="Redo", width=10, command= lambda: [start_team1(), clear()]).grid(row=4, column=2)
【问题讨论】:
标签: python-3.x user-interface tkinter