我正在尝试在苹果菜单托盘(右上角)中创建一个界面,当您按下按钮时,它会弹出一个 tkinter 界面。这是一段代码。
import rumps
from tkinter import *
import random
from rumps.rumps import quit_application
class Application:
def __init__(self, master):
frame = Frame(master)
frame.pack()
btn_one = Button(master, text='Exit', command=quit)
btn_one.pack(side=BOTTOM)
def sad_message():
l = {'Awww you closed me :(' : 'Sorry','Catastrophic Error: you closed your favorite app' : 'OH NO',
'User Error: Please replace user' : 'Burned',
'RUI has alerted Apple of your anti-Steve Jobs energy, please proclaim Steve Jobs as the second coming of christ in order to countinue' : 'Heil Steve Jobs',
}
message, okay = random.choice(list(l.items()))
return message, okay
class RuiApp(rumps.App):
def __init__(self):
rumps.debug_mode(True)
super(RuiApp, self).__init__("RUI")
self.menu = ["Vocal Interface", "Text Interface", "Close",]
@rumps.clicked("Vocal Interface")
def Vocal_Interface(haha, stinky):#variables are placeholder arguments but are never used,
root_text = Tk()
app_text = Application(root_text)
root_text.title('Text-Interface')
root_text.minsize(300,300)
root_text.mainloop()
@rumps.clicked("Text Interface")
def text_interface(self):
pass
@rumps.clicked("Close")
def close_thingy(notification_argument,quit_argument):
message, okay = sad_message()
rumps.alert(message = message, ok=okay)
while __name__ == '__main__':
App = RuiApp()
App.run()
当我按下“Vocal_interface”时,我得到了错误<MenuItem: ['Vocal Interface' -> []; callback: <function RuiApp.Vocal_Interface at 0x7fb3a075eb80>]> 2021-10-12 00:14:48.417 Python[10730:298256] -[NSApplication _resetAutoreleasePool]: unrecognized selector sent to instance 0x7fb39e953230,我正在寻找解决方案,但我永远无法弄清楚。