我的代码在没有OOP的情况下运行良好
现在我正试图用面向对象的方法实现它,但不知怎么的导致了一些错误。你知道吗
有人能帮忙吗?你知道吗
顺便说一句,错误是:
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2059, in _setup self.tk = master.tk AttributeError: class MainInterface has no attribute 'tk'"
from Tkinter import *
import tkFont
class MainInterface:
def __init__(self, master):
self.master = master
# Main interface created
master.title("Dijkstra's Algorithm Solution Demonstrator")
# Title for the main interface
self.TNR24 = tkFont.Font(family="Times New Roman", size=24, weight="bold")
self.TNR28 = tkFont.Font(family="Times New Roman", size=28, weight="bold")
# Two font types that can be used later
master.overrideredirect(True)
master.geometry("{0}x{1}+0+0".format(master.winfo_screenwidth(), master.winfo_screenheight()))
# Formats the interface so that it would be in full screen
self.MainTitle = Label(MainInterface, text="Dijkstra's Algorithm Solution Demonstrator", bg="white", font=self.TNR28)
self.InterfaceMenu = Menu(MainInterface)
self.MainInterface.config(menu=self.InterfaceMenu)
self.submenu1 = Menu(self.InterfaceMenu)
self.InterfaceMenu.add_cascade(label="File", menu=self.submenu1)
self.submenu2 = Menu(self.InterfaceMenu)
self.InterfaceMenu.add_cascade(label="Help", menu=self.submenu2)
self.submenu2.add_command(label="details")
self.MainInterfaceButton1 = Button(MainInterface, text="Input New Question", font=self.TNR24, command=create_window)
self.MainInterfaceButton2 = Button(MainInterface, text="Load Up Existing Question", font=self.TNR24)
self.MainInterfaceButton3 = Button(MainInterface, text="Identify Incorrectly Applied Algorithms", font=self.TNR24)
# Three main buttons created for that interface
self.ExitButton = Button(MainInterface, text="Exit", command=self.exit_window)
# Exit button created
self.MainTitle.pack()
# Packs the main title onto the interface
self.MainInterfaceButton1.place(x=340, y=200, width=600, height=100)
self.MainInterfaceButton2.place(x=340, y=350, width=600, height=100)
self.MainInterfaceButton3.place(x=340, y=500, width=600, height=100)
self.ExitButton.place(x=1240, y=670, width=40, height=30)
# Places the buttons at desirable places
self.MainInterface.configure(background="white")
# Makes the background colour white
def exit_window(self):
self.quit()
# Function for existing the interface
def main():
root=Tk()
Lookatthis=MainInterface(root)
root.mainloop
if __name__ == "__main__":
main()
你可能有问题,因为你必须在
Label
、Button
等中使用master
而不是MainInterface
-
MainInterface
不是Tkinter小部件,也不能是其他小部件的父(主)部件。你知道吗相关问题 更多 >
编程相关推荐