我正在尝试编写一个 python 程序,并且我希望能够在单击另一个类时更新另一个类的按钮。例如:
gui.py 文件:
class main(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, background="white")
self.parent = parent
self.initUI()
#menu bar
menu = Menu(parent)
parent.config(menu=menu)
parent.option_add('*tearOff', FALSE)
#file menu
fileMenu = Menu(menu)
menu.add_cascade(label="File", menu=fileMenu)
fileMenu.add_command(label="New Show", command=shows.saves.open)
fileMenu.add_command(label="Save Show", command=shows.saves.save)
fileMenu.add_command(label="Save Show As", command=shows.saves.saveas)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=self.quit)
#edit menu
editMenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editMenu)
editMenu.add_command(label="Copy (ctrl+c)", command=shows.saves.open)
editMenu.add_command(label="Cut (ctrl+x)", command=shows.saves.save)
editMenu.add_command(label="Paste (ctrl+v)", command=shows.saves.saveas)
#insert menu
insrtMenu = Menu(menu)
menu.add_cascade(label="Insert", menu=insrtMenu)
insrtMenu.add_command(label="Add Audo Cue (ctrl + 1)", command=shows.saves.open)
insrtMenu.add_command(label="Add Memo Cue (ctrl + 2)", command=shows.saves.save)
#toolbar
toolbar = Frame(parent)
b1 = Button(toolbar, text="Mode = Setup", command=m.mode.switch)
b1.pack(side=LEFT, padx=2, pady=2)
b2 = Button(toolbar, text="Preview", command=shows.saves.open)
b2.pack(side=LEFT, padx=2, pady=2)
b3 = Button(toolbar, text="Edit", command=shows.saves.open)
b3.pack(side=LEFT, padx=2, pady=2)
b4 = Button(toolbar, text="Edit", command=shows.saves.open)
b4.pack(side=LEFT, padx=2, pady=2)
toolbar.pack(side=TOP, fill=X)
#main table
screen_width = parent.winfo_screenwidth()
screen_height = parent.winfo_screenheight()
listbox = Listbox(parent, width=screen_width, height=screen_height, bg="black", fg="white")
listbox.pack()
listbox.insert(END, "Cue1 - Rain")
def initUI(self):
self.parent.title("PyCue ALPHA 0.1")
#self.pack(fill=BOTH, expand=1)
m.py 文件:
class mode():
def switch():
if b1["text"] == "Mode = Setup":
b1["text"] = "Mode = Run"
else:
b1["text"] = "Mode = Setup"
有人可以解释一下我该怎么做吗?我所有的(非常 alpha)代码都在 github 上:https ://github.com/codefail/PyCue如果你想查看整个事情。