为什么我的窗口小部件没有显示在第三个屏幕上

时间:2018-10-19 15:17:07

标签: python tkinter

在第二个屏幕上选择2个Duelist时,程序将显示第三个屏幕,该屏幕应显示2个标签和2个输入小部件,以便用户输入玩家的姓名。但是我似乎无法弄清楚为什么这些小部件没有显示出来。涉及此问题的代码部分是TwoPlayer类的代码块。谢谢!

import tkinter as tk


largeFont = ("Veranda", 18)
field1 = 'Duelist 1', 'Duelist 2' 
names = []

class Yugioh_backEnd(tk.Tk):
    #set default initializion 
    def __init__(self, *args, **kwargs):


        tk.Tk.__init__(self, *args, **kwargs)

        tk.Tk.wm_title(self, "YuGiOh Duel Calculator")

        #containers
        container = tk.Frame(self)

        #set pack method for container
        container.pack(side="top", fill="both", expand=True)

        #set grid method for container
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        #selects which frame to show
        self.frames = {}

        for F in (StartPage, NumPlayers, TwoPlayer):

            frame = F(container, self)

            self.frames[F]=frame

            frame.grid(row=0, column=0, sticky="nsew")

        #show Frame
        self.show_frame(StartPage)


    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()

class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        #greet the user
        greeting = tk.Label(self, text = "Welcome to\n YuGiOh Duel Calculator!", font = largeFont)
        greeting.pack(pady=(10,40),padx=30)

        #Enter the next window
        lets_duel = tk.Button(self, text="Lets Duel!!!",                command=lambda: controller.show_frame(NumPlayers))
        lets_duel.pack(pady=(0,30),padx=30)

class NumPlayers(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        #prompt for players quantity
        prompt1 = tk.Label(self, text = "How many duelist?", font = largeFont)

        prompt1.pack(pady=(10,40),padx=30)

        #Number of players
        twoPlayers = tk.Button(self, text = "2 Duelists", command=lambda: controller.show_frame(TwoPlayer))

        return1 = tk.Button(self, text="Return Home", command=lambda: controller.show_frame(StartPage))

        #Add buttons to frame
        return1.pack(pady=(0,30),padx=30)
        twoPlayers.pack(pady=(0,10),padx=30)


#Two player mode
class TwoPlayer(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)


        def makeform(field1):

           for field in field1:
              row = tk.Frame()
              lab = tk.Label(row, width=15, text=field, anchor='w')
              ent = tk.Entry(row)
              row.pack(side="top", padx=5, pady=5)
              lab.pack(side="left")
              ent.pack(side="right")
              names.append((field, ent))
           return names

        if __name__ == ("__init__"):
               ents = makeform(field1) 
               b1 = tk.Button(text='Show',
                      command=lambda: controller.show_frame(StartPage))
               b1.pack(padx=5, pady=5)



app = Yugioh_backEnd()
app.mainloop()

0 个答案:

没有答案