Skip to content

Commit 9e847e4

Browse files
authored
Create Docked_UI.py
1 parent 08938bf commit 9e847e4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Docked_UI.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from tkinter import *
2+
from robolink import *
3+
import threading
4+
5+
# Create a new window
6+
window = tkinter.Tk()
7+
8+
# Close the window
9+
def onClose():
10+
window.destroy()
11+
quit(0)
12+
13+
# Trigger Select button
14+
# IMPORTANT: We need to run the action on a separate thread because
15+
# (otherwise, if we want to interact with RoboDK window it will freeze)
16+
def on_btnSelect():
17+
def thread_btnSelect():
18+
# Run button action (example to select an item and display its name)
19+
RDK = Robolink()
20+
item = RDK.ItemUserPick('Select an item')
21+
if item.Valid():
22+
RDK.ShowMessage("You selected the item: " + item.Name())
23+
24+
threading.Thread(target=thread_btnSelect).start()
25+
26+
# Set the window title (must be unique for the docking to work, try to be creative)
27+
window_title = 'RoboDK API Docked Window'
28+
window.title(window_title)
29+
30+
# Delete the window when we close it
31+
window.protocol("WM_DELETE_WINDOW", onClose)
32+
33+
# Add a button
34+
btnSelect = Button(window, text='Trigger on_btnSelect', height=5, width=60, command=on_btnSelect)
35+
btnSelect.pack(fill=X)
36+
37+
# Embed the window
38+
EmbedWindow(window_title)
39+
40+
# Run the window event loop. This is like an app and will block until we close the window
41+
window.mainloop()

0 commit comments

Comments
 (0)