'module'对象没有属性'TK'

时间:2016-08-23 23:58:56

标签: python user-interface tkinter

我是学习GUI的初学者。

我的python版本是2.7,我正在使用Windows。

我在文件夹中搜索过tkinter,只有一个python文件位于C:\python27

这是我的代码:

import Tkinter as tk 

class Electronic_Signature_User_Program(tk.TK):
    def __init__(self,*args,**kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        container = tk.Frame(self)
        container.pack(side = "top",fill = "both",expand = True)
        container.grid_rowconfigure(0,weight=1)
        container.grid_columnconfigure(0,weight=1)

        self.frames = {}

        for F in (Loginpage, Login_Confirm):
            frame = Loginpage(container,self)
            self.frames[Loginpage] = frame
            frame.grid(row=0,column=0,sticky="nsew")

        self.show_frame(Loginpage)

    def show_frame(self,cont):
        frame = self.frames[cont]
        frame.tkraise()

class Loginpage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        button1 = tk.Button(self,text="Login_Confirm",command=lambda:controller.show_frame(Login_Confirm))
        button1.pack()

class Login_Confirm(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        button2 = tk.Button(self,text="Loginpage",command=lambda:controller.show_frame(Loginpage))
        button2.pack()


app = Electronic_Signature_User_Program()
app.title('UoL 702 Electrinic Signature User Program')
app.mainloop()

1 个答案:

答案 0 :(得分:-1)

在第一个班级声明中,您TK应该是Tk