简体   繁体   English

Python/Tkinter 前端框架

[英]Python/Tkinter Frontend Frame

When opened normally Fullscreen正常打开时全屏

i'm working on my first ever project, and i'm using python/tkinter.我正在做我的第一个项目,我正在使用 python/tkinter。 i've come up with this design(above) but i can't make it responsive.我想出了这个设计(上面),但我不能让它响应。

i want the bottom section to stay the same but i want to extend the top part through the bottom.我希望底部保持不变,但我想将顶部延伸到底部。

from tkinter import *

root = Tk()

topFrame = Frame(root)
topFrame.pack(side=TOP, fill=BOTH)

scrollbar = Scrollbar(topFrame)
scrollbar.pack(side=RIGHT, fill=Y)

listbox = Listbox(topFrame)
listbox.pack(fill=BOTH)

for i in range(100):
    listbox.insert(END, i)

#attaching list and scroll #附加列表并滚动

listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)

#bottom frame

bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM, fill=X)

#bottom laft frame #底部后框架

b_leftFrame = Frame(bottomFrame)
b_leftFrame.pack(side=LEFT, fill=X)

#defining label #定义标签

label1 = Label(b_leftFrame, text="Title")
label1.grid(row=0, column=0, sticky=E)

label2 = Label(b_leftFrame, text="Author")
label2.grid(row=0, column=2, sticky=E)

label3 = Label(b_leftFrame, text="Publisher")
label3.grid(row=0, column=4, sticky=E)

label4 = Label(b_leftFrame, text="Year")
label4.grid(row=0, column=6, sticky=E)

label5 = Label(b_leftFrame, text="Translator")
label5.grid(row=0, column=8, sticky=E)

#defining labels #定义标签

title_text =StringVar()
entry1 = Entry(b_leftFrame, textvariable=title_text)
entry1.grid(row=0, column=1)

author_text =StringVar()
entry2 = Entry(b_leftFrame, textvariable=author_text)
entry2.grid(row=0, column=3)

publisher_text =StringVar()
entry3 = Entry(b_leftFrame, textvariable=publisher_text)
entry3.grid(row=0, column=5)

year_text =StringVar()
entry4 = Entry(b_leftFrame, textvariable=year_text)
entry4.grid(row=0, column=7)

translator_text =StringVar()
entry4 = Entry(b_leftFrame, textvariable=translator_text)
entry4.grid(row=0, column=9)

#bottom right #右下角

b_rightFrame = Frame(bottomFrame)
b_rightFrame.pack(side=RIGHT)

#buttons #按钮

b1=Button(b_rightFrame, text="View All", width=12)
b1.grid(row=2, column=3)

b1=Button(b_rightFrame, text="Search Entry", width=12)
b1.grid(row=3, column=3)

b1=Button(b_rightFrame, text="Add Entry", width=12)
b1.grid(row=4, column=3)

b1=Button(b_rightFrame, text="Update selected", width=12)
b1.grid(row=5, column=3)

b1=Button(b_rightFrame, text="Delete selected", width=12)
b1.grid(row=6, column=3)

b1=Button(b_rightFrame, text="Close", width=12)
b1.grid(row=7, column=3)



root.mainloop()

The problem here is that the topFrame widget, which contains the Listbox, is not taking all the available space.这里的问题是包含列表框的 topFrame 小部件没有占用所有可用空间。

Try replacing your:尝试更换您的:

topFrame.pack(fill=BOTH)

with:与:

topFrame.pack(fill=BOTH, expand=YES)

This will make the topFrame expand once you maximize the window.一旦最大化窗口,这将使 topFrame 展开。

Also, in order to make the listbox expand as well, replace your此外,为了使列表框也展开,请替换您的

listbox.pack(fill=BOTH)

with:与:

listbox.pack(fill=BOTH, expand=YES)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM