Python 3.x Tkinter蟒蛇3带包装的插入表
我发现TKinter上有多个页面的示例,我试图使用它,但我遇到了一个问题,在第一个页面中,我希望有一个表返回我从DB读取的一些值,问题是我发现的代码使用了pack(),因此我无法获取列和行 有人知道如何介绍一张桌子吗?我试着搜索,但没有找到太多Python 3.x Tkinter蟒蛇3带包装的插入表,python-3.x,tkinter,Python 3.x,Tkinter,我发现TKinter上有多个页面的示例,我试图使用它,但我遇到了一个问题,在第一个页面中,我希望有一个表返回我从DB读取的一些值,问题是我发现的代码使用了pack(),因此我无法获取列和行 有人知道如何介绍一张桌子吗?我试着搜索,但没有找到太多 TITLE_FONT = ("Helvetica", 18, "bold") text_font = ("Helvetica", 14) class SampleApp(tk.Tk): def __init__(self, *args, **
TITLE_FONT = ("Helvetica", 18, "bold")
text_font = ("Helvetica", 14)
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(10, weight=1)
container.grid_columnconfigure(10, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Home", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
button1 = tk.Button(self, text="Users",
command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Courses",
command=lambda: controller.show_frame("PageTwo"))
button1.pack(side="left")
button2.pack(side="left")
#########################
#I want Introduce my table here with 9 columns and dynamic lines
#########################
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="User Page", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Courses Page", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
我曾经尝试过类似的方法,但问题是每次在grid命令中都会出现错误:
for j in range(10):
for i in range(10):
e = tkinter.Entry(f)
e.grid(column=i,row=j, borderwidth=0)
es[i,j] = e
在页面上,您可以使用
pack()
放置Frame()
,然后在该框架内使用grid()
放置表格 什么错误?始终输入问题完整错误消息。还有其他有用的信息。顺便说一句:您可以使用pack()
放置Frame()
,在这个框架内,您可以使用grid()
放置小部件。您甚至可以放置另一个框架
,在这个框架内,您可以再次使用pack()
。您有没有理由不在这一页中将pack
调用切换到grid
?没有什么能阻止你这么做。嗨@BryanOakley,我没有;我不知道这是可能的,我是Tkinter的新手,请给我一些如何做的建议?@furas当我用网格运行代码时,我收到以下错误:错误选项“-borderwidth”:必须是-column,-columnspan,-in,-ipadx,-ipady,-padx,-pady,-row,-rowspan或-sticky我如何将框架放入包中?your_Frame.pack()
。稍后,您可以使用grid()
-ie.标签(您的框架,…).grid()将元素放入该框架中