如何在 mac 触摸栏中显示 tkinter 按钮

How to show tkinter buttons in mac touch bar

我有一个 tkinter 应用程序,想在 Mac 触控栏中显示它的一些按钮。 例如

from tkinter import *

root = Tk()
    
send_button = Button(text = "Send",bg = 'sky blue',fg = 'black',font = "size 15",pady = 5)
send_button.grid()
    
root.mainloop()

所以我想集成 send_button 以显示在 Touch Bar 中,那么在 tkinter 中有没有办法做到这一点。

有一个名为 PyTouchBar 的包。我认为这会有所帮助。 https://github.com/Maxmad68/PyTouchBar/wiki

举个例子:

root = Tk()
PyTouchBar.prepare_tk_windows(root)


def function(button):
    print('Button clicked!')


button = PyTouchBar.TouchBarItems.Button(title='Click me!', action=function)
PyTouchBar.set_touchbar([button])

root.mainloop()