【发布时间】:2020-09-01 15:21:07
【问题描述】:
我的预期输出是:
_______________________________
|-------------------------------|
| EXAMPLE |
| Label1 |
| ______ _______ ______ |
|| | | | | | |
|| | | | | | |
||______| |_______| |______| |
|_______________________________|
这里我想将这三个按钮放置在一个固定的距离和中心,这意味着按钮的大小是固定的,如果用户试图扩大窗口的大小,应该保持按钮之间的距离比
这是我的代码:
from tkinter import *
window = Tk()
window.minsize(710, 500)
window.state('zoomed')
window.title('Example')
frame = Frame(window)
frame.pack(fill=BOTH, expand=True)
frame2 = Frame(window)
frame2.pack(fill=BOTH, expand=True)
Label(frame, text="Example", fg='red3',
font=('Eras Bold ITC', '65', 'bold')).pack(anchor = 'n', pady = 50)
Label(frame, text="Label2", fg='blue',
font=('Calibri', '25', 'bold')).pack(anchor = 'e', padx = 40)
Button(frame2, height='10', width='20', text = 'image1').grid(row = 0, column = 0, padx = 20)
Button(frame2, height='10', width='20', text = 'image2').grid(row = 0, column = 6, padx = 20)
Button(frame2, height='10', width='20', text = 'image3').grid(row = 0, column = 12, padx = 20)
mainloop()
这里我使用了网格方法,但我尝试过应用
pack(),但它会将按钮放在第一个按钮的下方
输出: https://i.stack.imgur.com/ItxvB.jpg
预期输出:即使在展开的窗口中(编辑后的图像) https://i.stack.imgur.com/Koe34.jpg
【问题讨论】:
-
尝试将
place()与relx=0.25、relx=0.5和relx=0.75分别用于3 个按钮,将rely=0.5用于所有3 个按钮。
标签: python button tkinter grid pack