[英]Python frames auto resizing
我已经创建了4帧,但是当尝试在第4帧中包装标签时,所有帧都会自动调整大小,任何人都可以看看并告知我在做什么错。 我是python的新手,并使用python 3.6。
from tkinter import *
import time
localtime = time.asctime(time.localtime(time.time()))
root = Tk()
x = root.winfo_screenwidth()
y = root.winfo_screenheight()
root.geometry("%dx%d+0+0" %(x,y))
root.resizable(0,0)
frameinfo = Frame(root, width=x, height=100 , bg='powder blue', relief=SUNKEN)
frameinfo.pack(side=TOP,fill=BOTH, expand=YES)
framebutton = Frame(root, width=300, height=y-100, bg='dark grey', relief=SUNKEN)
framebutton.pack(side=LEFT,fill=BOTH, expand=YES)
frameradio = Frame(root, width=x-300, height=50, bg='light yellow', relief=SUNKEN)
frameradio.pack(side=TOP, fill=BOTH, expand=YES)
frameinput = Frame(root, width=x-300, height=y-150, bg='light green')
frameinput.pack(side=LEFT, fill=BOTH, expand=YES)
clock = Label(frameinfo, font =('aerial', 30, 'bold'), fg='blue', bg='powder blue')
clock.pack(side=RIGHT)
lblinfo = Label(frameinfo, text = "Cloning Tool", font =('aerial', 40, 'bold'), fg='black', bg='powder blue').pack()
def tick():
s =time.strftime('%d-%m-%y %H:%M:%S')
clock.config(text=s)
clock.after(200,tick)
tick()
butCapClone = Button(framebutton, text='Clone', borderwidth=5,width=20,height=2, font=9, command=showcapwindow).grid(row=0, padx=10, pady=20)
butexitClone = Button(framebutton, text='Exit', borderwidth=5,width=20,height=2, font=9, command=root.quit).grid(row=1, padx=10, pady=4)
modes = [('None','0'),('CAP','1'),('CAPTWO v1','2'),('CAPTWO v2','3'),]
radioclonetype = IntVar()
radioclonetype.set('0')
for text,mode in modes:
Radiobutton(frameradio, text=text, variable=radioclonetype, value=mode, font=('aerial',15), bg='light yellow', fg='purple').pack(side=LEFT)
labelprojectcode = Label(frameinput, text = "Project code(3 Characters")
labelprojectcode.pack(side=TOP)
# inputprojectcode = Entry(frameinput, fg='black', font=('aerial',15,'bold')).grid(row=0,column=1)
root.mainloop()
框架会根据子窗口小部件的大小需求而扩展或收缩,因为有额外的空间。您的标签超出了我的1980x1080分辨率,并且最后一帧的内容不再可见。 注释掉root.resizable(0,0)
看看会发生什么:
#root.resizable(0,0)
这似乎是因为pack
工程相对于同级pack
S和最后一个叫pack
被赋予它要求同时还装配给所有选项的空间最小pack
秒。 例如,交换以下职位:
frameradio.pack(side=TOP, fill=BOTH, expand=YES)
与:
frameinput.pack(side=LEFT, fill=BOTH, expand=YES)
您将获得几乎全新的布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.