Skip to content

Integrate into your project

Maxmad68 edited this page Jun 19, 2020 · 3 revisions

Currently, PyTouchBar is compatible only with Tkinter and Pygame. To make your window "hosting" a TouchBar, you'll need to prepare the window with the following command, depending on the graphic module you are using.

At this point, the window is ready to host a TouchBar, but the TouchBar is still empty.

We will see on the next page how to add items in it.

Tkinter

If you are using Tkinter, you'll need to use this command:

PyTouchBar.prepare_tk_windows(window1, window2, ...)

For example, a typical example would be:

root = Tk()
PyTouchBar.prepare_tk_windows(root)
lbl = Label(root, text="Button")
lbl.pack()
root.mainloop()

Another way to use PyTouchBar with Tkinter, is to init a TouchBarTk instead of a Tk (it uses the same parameters than Tk()

root = PyTouchBar.TouchBarTk()
lbl = Label(root, text="Button")
lbl.pack()
root.mainloop()

Pygame

If you are using PyGame, you'll need to use this command just after setting the window parameters:

 PyTouchBar.prepare_pygame()

For example, a typical example would be:

pygame.init()
surface = pygame.display.set_mode((100,200))
PyTouchBar.prepare_pygame()
pygame.display.set_caption('Title')

while True:
  	for event in pygame.event.get():
		  if event.type == pygame.QUIT:
			  pygame.quit()
			  break

Clone this wiki locally