我有个问题.我认为一个类可以基于一个对象或以前定义类.当我将其更改为类Application(对象)时:它不起作用.你能告诉我为什么它不起作用,为什么下面的代码有效或为什么类应用程序(框架)有效?Frame不是先前定义的对象而不是对象.对不起我的英语不好.这是我的代码:
# Lazy Buttons
# Demonstrates using a class with tkinter
from tkinter import *
class Application(Frame): #
""" A GUI application with three buttons. """
def __init__(self, master):
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create three buttons that do nothing. """
# create the first Button
self.bttn1 = Button(self, text= "I do nothing.")
self.bttn1.grid()
# create second button
self.bttn2 = Button(self)
self.bttn2.grid()
self.bttn2.configure(text="Me too!")
# create third button
self.bttn3 = Button(self)
self.bttn3.grid()
self.bttn3["text"] = "Same here!"
# main …Run Code Online (Sandbox Code Playgroud)