这里的小问题,我的代码看起来很干净但是没有出现tkinter GUI?似乎可以搞清楚。 GUI /代码用于报告表单类型。
感谢您的提前帮助
from tkinter import *
class FicheDeSignalement(Frame):
def __init__(self):
Frame.__init__(self)
programme = Frame()
programme.pack(side="top", fill="both", expand=True)
programme.grid_rowconfigure(0, weight=5)
programme.grid_columnconfigure(0, weight=5)
self.pages = {}
for onePage in (StartProgram, InformationsPage):
start_page = onePage(programme, self)
self.pages[onePage] = start_page
start_page.grid(row=0, column=0, sticky="nsew")
self.show_pages(StartProgram)
def show_pages(self, cont):
see_start_page = self.pages[cont]
see_start_page.tkraise()
class StartProgram(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent, controller)
label = Label(self, text="Fiche de Signalement", font=LARGE_FONT)
label.pack(padx=10, pady=10)
start_button = Button(self, text="Commencer", command=lambda: controller.see_page(InformationsPage))
start_button.pack()
class InformationsPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent, controller)
label = Label(self, text="Informations sur le suspect", font=LARGE_FONT)
label.pack(side="top", fill="both", expand=True, padx=10, pady=10)
person_suspected = Label(self, text="Prenom")
person_suspected.grid(row=0, column=0, padx=10, pady=10)
first_name = Entry(self)
first_name.grid(row=0, column=1, padx=10, pady=10)
person_suspected_2 = Label(self, text="Nom")
person_suspected_2.grid(row=0, column=2, padx=10, pady=10)
last_name = Entry(self)
last_name.grid(row=0, column=3, padx=10, pady=10)
person_height = Label(self, text="Grandeur")
person_height.grid(row=1, column=0, padx=10, pady=10)
size_height = Entry(self)
size_height.grid(row=1, column=1, padx=10, pady=10)
person_weight = Label(self, text="Poids")
person_weight.grid(row=1, column=2, padx=10, pady=10)
size_weight = Entry(self)
size_weight.grid(row=1, column=3, padx=10, pady=10)
app = FicheDeSignalement()
app.mainloop()
答案 0 :(得分:1)
除了缩进错误和缺少导入语句以及缺少LARGE_FONT
的定义之外,您还遇到此问题:
label = Label(self, text="Informations sur le suspect")
label.pack(side="top", fill="both", expand=True, padx=10, pady=10)
person_suspected = Label(self, text="Prenom")
person_suspected.grid(row=0, column=0, padx=10, pady=10)
label
和person_suspected
共享同一个父(self
),但其中一个使用pack
,另一个使用grid
。您不能将它们与共享父公共的小部件一起使用。您必须仅使用grid
或仅使用pack
。