[英]Problem with displaying Tkinter Frames inside another frame
Hi I am having troubles with tkinter frames.嗨,我在使用 tkinter 框架时遇到问题。 I was hoping to have a window with a main frame.
我希望有一个带主机的 window。 In that main frame I have a title label, top frame, and a bottom frame.
在那个主框架中,我有一个标题 label、顶部框架和底部框架。 I was hoping to use grid to place the title label and the top and bottom frame one after each other.
我希望使用网格将标题 label 和顶部和底部框架一个接一个地放置。 The issue I came across was the title label and the bottom frame was not displaying.
我遇到的问题是标题 label 并且底部框架没有显示。
heres my code:这是我的代码:
from tkinter import *
def addLabels(frame):
lbl_date = Label(frame, text="DATE(DD/MM/YYYY)").grid(row=0,column=0)
lbl_po = Label(frame, text="PO #").grid(row=0,column=1)
lbl_nikls = Label(frame, text="NIKLS").grid(row=0,column=2)
lbl_sro = Label(frame, text="SRO").grid(row=0,column=3)
lbl_hours = Label(frame, text="HOURS").grid(row=0,column=4)
lbl_otHours = Label(frame, text="OT HOURS").grid(row=0,column=5)
lbl_dot = Label(frame, text="D-OT HOURS").grid(row=0,column=6)
lbl_invoice = Label(frame, text="INVOICE #").grid(row=0,column=7)
def addEntry(frame):
entry_date = Entry(frame).grid(row=1,column=0)
entry_po = Entry(frame).grid(row=1,column=1)
chk_nikls = Checkbutton(frame, text="").grid(row=1, column=2)
chk_sro = Checkbutton(frame, text="").grid(row=1, column=3)
entry_hours = Entry(frame).grid(row=1,column=4)
entry_otHours = Entry(frame).grid(row=1,column=5)
entry_dot = Entry(frame).grid(row=1,column=6)
entry_invoice = Entry(frame).grid(row=1,column=7)
##create window
window = Tk()
#main fraime
mainframe = Frame(master=window, borderwidth=1, highlightbackground="black", highlightthickness=1)
##create and pack trinity header
lbl_title = Label(master=mainframe, text="Trinity Menu").grid(row=0)
##create frame for top view
top = Frame(master=mainframe, borderwidth=1, highlightbackground="black", highlightthickness=1).grid(row=1)
addLabels(top)
addEntry(top)
##create frame for bottom view
bottom = Frame(master=mainframe, borderwidth=1, highlightbackground="black", highlightthickness=1).grid(row=2)
addLabels(bottom)
## run program
window.mainloop()
If you could please help that would be greatly appreciated.如果你能请帮助,将不胜感激。 Thanks in advance.
提前致谢。
The first problem is: you never use place
, pack
or grid
on mainframe
.第一个问题是:你永远不会在
mainframe
上使用place
、 pack
或grid
。 Use something like:使用类似的东西:
mainframe = Frame(master=window, borderwidth=1, highlightbackground="black", highlightthickness=1)
mainframe.pack()
The second one: you create a frame by using e=Entry(...)
.第二个:您使用
e=Entry(...)
创建一个框架。 Then e
is an object of class Entry
.然后
e
是 class Entry
的 object 。 You place it py using a=e.grid(...)
etc. But then a
is of type None.您使用
a=e.grid(...)
等将其放置为 py。但是a
的类型为 None。 So a=e.grid(...)
returns the same a
( NoneType
) as a=Entry(...).grid(...)
, but you are not interested in that but in e
.因此
a=e.grid(...)
返回与a=Entry(...).grid(...)
相同a
( NoneType
),但您对此不感兴趣,而是对e
感兴趣。 This is nor jQuery.这也不是 jQuery。 So use:
所以使用:
lbl_title = Label(master=mainframe, text="Trinity Menu")
lbl_title.grid(row=0)
Hope that's helpful!希望这会有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.