Python帧自动调整大小

2024-09-27 21:28:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经创建了4帧,但当试图在我的第4帧打包一个标签,所有帧自动调整大小,请任何人看看,并建议我做错了什么事。我对python和python3.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()

Tags: texttimebluerootwidthfillframeside
1条回答
网友
1楼 · 发布于 2024-09-27 21:28:02

如果有额外的空间,帧会根据子窗口小部件的大小需求进行扩展或收缩。您的标签超出了我的1980x1080分辨率,最后一帧的内容将不再可见。注释掉root.resizable(0,0)看看会发生什么:

#root.resizable(0,0)

这似乎是因为pack相对于兄弟pack工作,最后一个被调用的pack得到了它所需的最小空间量,同时仍然适合所有pack的选项。例如,交换以下位置:

frameradio.pack(side=TOP, fill=BOTH, expand=YES)

使用:

frameinput.pack(side=LEFT, fill=BOTH, expand=YES)

你会得到一个几乎完全新的布局

相关问题 更多 >

    热门问题