Python2.7Tkinter类

Python2.7Tkinter类,python,class,user-interface,python-2.7,tkinter,Python,Class,User Interface,Python 2.7,Tkinter,我试图用tkinter创建一个基类,它可以显示解析到它的任何变量的内容 我的目标是拥有多个类,这些类将变量传递给要显示的类。到目前为止,我有以下代码,但我无法使其按预期工作 任何帮助都将不胜感激,谢谢 from Tkinter import * class interface: def __init__(self, root): root.title("Testing tkinter and labels") root.geometry("600x200

我试图用tkinter创建一个基类,它可以显示解析到它的任何变量的内容

我的目标是拥有多个类,这些类将变量传递给要显示的类。到目前为止,我有以下代码,但我无法使其按预期工作

任何帮助都将不胜感激,谢谢

from Tkinter import *

class interface:
    def __init__(self, root):
        root.title("Testing tkinter and labels")
        root.geometry("600x200")

    def text(str1, str2):
        Label(root, text = str1).pack(expand=1)
        Label(root, text = str2).pack(expand=1)

        app = Frame(root)
        app.pack(side = 'bottom')
        button1 = Button(app, text="Next")
        button1.pack()

str1 = "hello"
str2 = "bye"
root = Tk()
interface(root)
interface.text(str1, str2)
root.mainloop()

我想你应该有这个:

def text(self, str1, str2): #<-- you forgot self
应该是:

int_obj = interface(root) # you need to create a variable to hold an instance of the interface you create. Otherwise, its immediately deleted.
int_obj.text(str1, str2)

为什么它不起作用?有错误吗?
int_obj = interface(root) # you need to create a variable to hold an instance of the interface you create. Otherwise, its immediately deleted.
int_obj.text(str1, str2)