-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from cpvalente/chore/examples
Chore/examples
- Loading branch information
Showing
3 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""(Very) Simple Example of using Tkinter with StupidArtnet. | ||
It creates a simple window with a slider of value 0-255 | ||
This value is streamed in universe 0 channel 1 | ||
Note: The example imports stupid artnet locally from | ||
a parent folder, real use import would be simpler | ||
""" | ||
|
||
from stupidArtnet.StupidArtnet import StupidArtnet | ||
from tkinter import * | ||
|
||
|
||
def updateValue(val): | ||
"""Callback from slider onchange. | ||
Sends the value of the slider to the artnet channel.""" | ||
|
||
global stupid | ||
stupid.set_single_value(1, slider_val.get()) | ||
|
||
|
||
def cleanup(): | ||
"""Cleanup function for when window is closed. | ||
Closes socket and destroys object.""" | ||
print('cleanup') | ||
|
||
global stupid | ||
stupid.stop() | ||
del stupid | ||
|
||
global window | ||
window.destroy() | ||
|
||
|
||
# ARTNET CODE | ||
# ------------- | ||
|
||
# Create artnet object | ||
stupid = StupidArtnet() | ||
|
||
# Start persistent thread | ||
stupid.start() | ||
|
||
|
||
# TKINTER CODE | ||
# -------------- | ||
|
||
# Create window object | ||
window = Tk() | ||
|
||
# Hold value of the slider | ||
slider_val = IntVar() | ||
|
||
# Create slider | ||
scale = Scale(window, variable=slider_val, | ||
command=updateValue, from_=255, to=0) | ||
scale.pack(anchor=CENTER) | ||
|
||
# Create label with value | ||
label = Label(window) | ||
label.pack() | ||
|
||
# Cleanup on exit | ||
window.protocol("WM_DELETE_WINDOW", cleanup) | ||
|
||
# Start | ||
window.mainloop() |