def test_enable(): a = App() s = Slider(a) enable_test(s) a.destroy()
pantilthat.set_all(0, 0, 0, 0) pantilthat.show() pantilthat.pan(0) pantilthat.tilt(-20) exit() # GUI Setings app = App(bg ="lightgrey", title="Pimoroni Interactive Cam V1.5", width=1050, height=400, layout="grid") pan_txt = Text(app, text="R Pan L", width=17, grid=[1,0], align="left") pan_txt.text_color="blue" position_txt = Text(app, text="Postition", width=10, color="blue", grid=[0,1], align="left") pan_set = Slider(app, command=set_pan_tilt, start=-90, end=90, width=150, height=15, grid=[1,1], align="left") # sets pan value pan_set.value = 0 pan_set.bg="yellow" reset_position = PushButton(app, command=position_reset, text="Position Reset", width=14, grid=[2,1], align="left") reset_position.text_color="blue" tilt_txt = Text(app, text="U Tilt D", width=17, grid=[3,0], align="left") tilt_txt.text_color="blue" tilt_set = Slider(app, command=set_pan_tilt, start=-90, end=90, width=150, height=15, grid=[3,1], align="left") # sets tilt value tilt_set.value = -20 tilt_set.bg="yellow" lights_txt = Text(app, text="Lighting", width=10, color="blue", grid=[0,4], align="left")
def red_slider_changed(red_value): global red1 red1 = red_value app.bgcolor('#%02x%02x%02x' % (int(red1) * 2.55, int(green1) * 2.55, int(blue1) * 2.55)) RED.ChangeDutyCycle(100 - float(red1)) def green_slider_changed(green_value): global green1 green1 = green_value app.bgcolor('#%02x%02x%02x' % (int(red1) * 2.55, int(green1) * 2.55, int(blue1) * 2.55)) GREEN.ChangeDutyCycle(100 - float(green1)) def blue_slider_changed(blue_value): global blue1 blue1 = blue_value app.bgcolor('#%02x%02x%02x' % (int(red1) * 2.55, int(green1) * 2.55, int(blue1) * 2.55)) BLUE.ChangeDutyCycle(100 - float(blue1)) app = App(bgcolor="white") red = Slider(app, command=red_slider_changed, start=0, end=100) green = Slider(app, command=green_slider_changed, start=0, end=100) blue = Slider(app, command=blue_slider_changed, start=0, end=100)
import os from guizero import App, Slider servo_min = 500 # uS servo_max = 2500 # uS servo = 2 # GPIO 18 def map(value, from_low, from_high, to_low, to_high): from_range = from_high - from_low to_range = to_high - to_low scale_factor = float(from_range) / float(to_range) return to_low + (value / scale_factor) def set_angle(angle): pulse = int(map(angle+90, 0, 180, servo_min, servo_max)) command = "echo {}={}us > /dev/servoblaster".format(servo, pulse) os.system(command) def slider_changed(angle): set_angle(int(angle)) app = App(title='Servo Angle', width=500, height=150) slider = Slider(app, start=-90, end=90, command=slider_changed, width='fill', height=50) slider.text_size = 30 app.display()
button6 = PushButton(app, text="r", grid=[1, 1]) button6.text_size = 20 button6.bg = "green" button6.when_left_button_pressed = direction_four button6.when_left_button_released = stop # Right button for torvalds button7 = PushButton(app, text="e", grid=[2, 1]) button7.text_size = 20 button7.bg = "red" button7.when_left_button_pressed = east button7.when_left_button_released = stop_two # Left button for torvalds button8 = PushButton(app, text="w", grid=[3, 1]) button8.text_size = 20 button8.bg = "red" button8.when_left_button_pressed = west button8.when_left_button_released = stop_two # Sliders to control the servos and pwm servo_slider1 = Slider(servo_window, start=-90, end=90, command=servo_movement) servo_slider1.bg = "magenta" servo_slider2 = Slider(servo_window, start=-90, end=90, command=servo_two_movement) servo_slider2.bg = "magenta" slider_three = Slider(servo_window, start=0, end=10, command=pwm_one) slider_three.bg = "aqua" slider_four = Slider(servo_window, start=0, end=10, command=pwm_two) slider_four.bg = "aqua" # display the App app.display()
from guizero import App, Slider from gpiozero import AngularServo from time import sleep # Servo calibration maxPulseW = 2.4 / 1000 minPulseW = .4 / 1000 # Function to control Servo with fader def servo_control1(s1_value): angle = float(s1_value) s1 = AngularServo(17, min_pulse_width=minPulseW, max_pulse_width=maxPulseW) s1.angle = angle sleep(0.5) def servo_control2(s2_value): angle = float(s2_value) s2 = AngularServo(27, min_pulse_width=minPulseW, max_pulse_width=maxPulseW) s2.angle = angle sleep(0.5) # Main Program if __name__ == '__main__': app = App(title="Servo Control Faders") slider1 = Slider(app, start=-90, end=90, width=400, command=servo_control1) slider2 = Slider(app, start=-90, end=90, width=400, command=servo_control2) app.display()
stream.start_stream() def push_stop(): stream.stop_stream() def change_gain_left(): global audio_gain_left audio_gain_left = slider_gain_left.value/100 def change_gain_right(): global audio_gain_right audio_gain_right = slider_gain_right.value/100 ##### <<<<<<<<< SETUP AUDIO STREAM >>>>>>>>> ##### p = pyaudio.PyAudio() stream = p.open(format = pyaudio.paInt16, channels = output_channels, rate = fs, output = True, stream_callback=playingCallback,output_device_index=output_index,frames_per_buffer=frame_size) stream.stop_stream() ##### <<<<<<<<< CONFIGURE GUI >>>>>>>>> ##### playback_app = App(title="Playback App") play_button = PushButton(playback_app,command=push_play,text="Play the Tune") play_button = PushButton(playback_app,command=push_stop,text="Stop the Tune") annotation = Text(playback_app,text="Adjust the Volume",size=20) slider_gain_left = Slider(playback_app,command=change_gain_left) slider_gain_right = Slider(playback_app,command=change_gain_right) playback_app.display()
def test_cascaded_properties(): a = App() s = Slider(a) cascaded_properties_test(a, s, True) a.destroy()
def test_inherited_properties(): a = App() inherited_properties_test(a, lambda: Slider(a), True) a.destroy()
def test_size(): a = App() s = Slider(a) size_pixel_test(s) a.destroy()
def test_events(): a = App() s = Slider(a) events_test(s) a.destroy()
def test_color(): a = App() s = Slider(a) color_test(s) a.destroy()
def test_text(): a = App() s = Slider(a) text_test(s) a.destroy()
def test_display(): a = App() s = Slider(a) display_test(s) a.destroy()
from guizero import App, Box, ButtonGroup, CheckBox, Combo, PushButton, Slider, Text, TextBox a = App(title="colors") text = Text(a, text="colors") check = CheckBox(a, "check me") combo = Combo(a, ["red", "blue"]) button = PushButton(a) slider = Slider(a) b = Box(a) textbox = TextBox(b, text="or colours") bgroup = ButtonGroup(b, ["cheese", "ham", "salad"], 1) #a.bg = (255,255,0) text.text_color = "red" text.text_size = 30 text.font = "verdana" #text.bg = "green" check.bg = "#d41789" combo.bg = "blue" combo.text_color = None combo.text_size = 24 #button.bg = "black" button.text_color = (255, 0, 255) button.font = "arial" button.text_size = 18 slider.bg = (123, 234, 12) #textbox.bg = "cyan" textbox.font = "courier" textbox.text_color = "#FF0000" b.bg = "cyan" b.font = "wingdings"
250, bottom_text.value, color=bottom_color.value, size=int(bottom_size.value), font="times new roman", ) app = App("Meme Generator") top_text = TextBox(app, "Top text", command=draw_meme) top_color = Combo(app, options=["black", "white", "red", "green", "blue", "orange"], command=draw_meme, selected="orange") top_size = Slider(app, start=20, end=40, command=draw_meme) Text(app, text="") bottom_text = TextBox(app, "Bottom text", command=draw_meme) bottom_color = Combo( app, options=["black", "white", "red", "green", "blue", "orange"], command=draw_meme, selected="blue") bottom_size = Slider(app, start=20, end=40, command=draw_meme) Text(app, text="") meme = Drawing(app, width="fill", height="fill") draw_meme()
from guizero import App, Text, Slider def cruise(speed): # "speed" holds the value of the slider txtSpeed.set("Speed set to " + speed + " mph") window = App(title="Slider Demo", width=270, height=150, layout="grid") Text(window, text=" ", grid=[0, 0]) # filler Text(window, text="\nSet Speed ", grid=[1, 1]) Slider(window, start=0, end=75, command=cruise, grid=[1, 2], align="left") Text(window, text=" ", grid=[2, 0]) # filler txtSpeed = Text(window, grid=[3, 2], align="left") txtSpeed.set("Speed set to 0 mph") window.display()
# Layout the app controls firstNameLabel = Text(app, text="First Name", grid=[0,0], align="left", size=10) lastNameLabel = Text(app, text="Last Name", grid=[0,1], align="left", size=10) countryLabel = Text(app, text="Country", grid=[0,2], align="left", size=10) addressLabel = Text(app, text="Address", grid=[0,3], align="left", size=10) firstNameText = TextBox(app, width=25, grid=[1,0]) lastNameText = TextBox(app, width=25, grid=[1,1]) countryCombo = Combo(app, options=['United Kingdom', 'United States', 'France'], selected='United Kingdom', grid=[1,2]) addressText1 = TextBox(app, width=25, grid=[1,3]) addressText2 = TextBox(app, width=25, grid=[1,4]) addressText3 = TextBox(app, width=25, grid=[1,5]) addressText4 = TextBox(app, width=25, grid=[1,6]) addressText5 = TextBox(app, width=25, grid=[1,7]) addressText6 = TextBox(app, width=25, grid=[1,8]) jobTitleLabel = Text(app, text="TBA", grid=[1,9], size=10) salaryLabel = Text(app, text="Salary : ", grid=[2,0,2,1], align="left", size=10) salaryScale = Slider(app, start=10000, end=100000, grid=[2,1,2,1], command=do_salaryScale, align="left") fullTimeCheckBox = CheckBox(app, text="Full-time?", grid=[2,2,2,1], command=do_fullTimeCheckBox, align="left") jobButtonGroup = ButtonGroup(app, options=["Programmer", "Developer", "Web Developer", "Designer"], selected=0, grid=[2,3,2,4], command=do_jobButtonGroup, align="left") okPushButton = PushButton(app, text="OK", command=do_okPushButton, grid=[2,9], padx=5, pady=5) closePushButton = PushButton(app, text="Close", command=do_closePushButton, grid=[3,9], padx=5, pady=5) app.display()
from guizero import App, Text, TextBox, PushButton, Slider def say_my_name(): welcome_message.set(my_name.get() + ", Welcome to my app!") def change_text_size(slider_value): welcome_message.font_size(slider_value) app = App(title="Hello, world!") welcome_message = Text(app, text="Welcome to my app", size=25, font="Impact", color="dark blue") my_name = TextBox(app, width=25) update_text = PushButton(app, command=say_my_name, text="Display my name") text_size = Slider(app, command=change_text_size, start=6, end=20) app.display()
def NamedSlider(label, value=0, command=None, start=-90, end=90): box = Box(app, layout="grid") label_text = Text(box, label, grid=[0, 0]) slider = Slider(box, command=command, start=start, end=end) return slider
from guizero import App, TextBox, Text, Slider, PushButton, Picture, Combo, CheckBox, ButtonGroup, Box app = App(title="different sizes", width=700, height=700) text = Text(app, "lets change some sizes") text.width = 30 text.height = 2 text_box = TextBox(app, "some text") text_box.width = 50 slider = Slider(app) slider.width = 300 slider.height = 30 button = PushButton(app) button.width = 20 button.height = 2 pic = Picture(app, image="guizero.gif") pic.width = 400 pic.height = 50 combo = Combo(app, ["martin", "laura", "rik"]) combo.width = 50 combo.height = 2 check = CheckBox(app, "tick me") check.width = 17 check.height = 2
print ("Started Led Console") chase_thread = threading.Thread(target=chase_runner, args=[strip]) chase_thread.start() try: app = App(title="Led Console", width=1280, height=900) color_box = Box(app, layout="grid", width="fill", align="top", border=True) color_title = Text(color_box, grid=[0,0], text="Color", align="left", width="fill") color_radio = ButtonGroup(color_box, horizontal=True, grid=[0,1], options=["Red", "Blue", "Green", "White"], command=update_color) color_text = Text(color_box, grid=[2,1], size=14, align="left") fill_text1 = Text(color_box, grid=[1,1], text=" ") fill_text = Text(color_box, grid=[1,2], text=" ") red_text = Text(color_box, grid=[1,3], size=14, align="left",text="Red") green_text = Text(color_box, grid=[1,4], size=14, align="left",text="Green") blue_text = Text(color_box, grid=[1,5], size=14, align="left",text="Blue") red_slider = Slider(color_box, grid=[2,3], command=update_red_value) green_slider = Slider(color_box, grid=[2,4], command=update_green_value) blue_slider = Slider(color_box, grid=[2,5], command=update_blue_value) bar_box = Box(app, layout="grid", width="fill", align="top", border=True) bar_title = Text(bar_box, grid=[0, 0], text="Bar Selection", align="left", width="fill") bar_1_sel = CheckBox(bar_box, grid=[1,1], text="Bar 1", command=update_bar_selection) bar_2_sel = CheckBox(bar_box, grid=[2,2], text="Bar 2", command=update_bar_selection) bar_3_sel = CheckBox(bar_box, grid=[1,3], text="Bar 3", command=update_bar_selection) bar_4_sel = CheckBox(bar_box, grid=[0,2], text="Bar 4", command=update_bar_selection) bar_5_sel = CheckBox(bar_box, grid=[5,1], text="Bar 5", command=update_bar_selection) bar_6_sel = CheckBox(bar_box, grid=[6,2], text="Bar 6", command=update_bar_selection) bar_7_sel = CheckBox(bar_box, grid=[5,3], text="Bar 7", command=update_bar_selection) bar_8_sel = CheckBox(bar_box, grid=[4,2], text="Bar 8", command=update_bar_selection) fill_text2 = Text(bar_box, grid=[0,4]) fill_text20 = Text(bar_box, grid=[3,0], text=" ")
global audio_gainR audio_gainR = slider_gainR.value/100 ##### <<<<<<<<< SETUP AUDIO STREAM >>>>>>>>> ##### p = pyaudio.PyAudio() stream = p.open(format = pyaudio.paInt16, channels = output_channels, rate = fs, output = True, stream_callback=playingCallback, output_device_index=output_index, frames_per_buffer=frame_size) stream.stop_stream() ##### <<<<<<<<< CONFIGURE GUI >>>>>>>>> ##### playback_app = App(title="Playback App") play_button = PushButton(playback_app,command=push_play,text="Start Playback") play_button = PushButton(playback_app,command=push_stop,text="Stop Playback") annotation = Text(playback_app,text="Adjust Input 1 Volume",size=20) slider_gainL = Slider(playback_app,command=change_gainL) annotation = Text(playback_app,text="Adjust Input 2 Volume",size=20) slider_gainR = Slider(playback_app,command=change_gainR) playback_app.display() # after window closed, close the stream to free up audio device stream.close()
modes_button = PushButton( app, command=camera_Modes, text='Modes', grid=[9,3], align='left' ) # Resolution combo Resolution_label = Text( app, text='Resolution', grid=[8,1], size=10, font='Helvetica', color='Blue', align='left' ) Resolution = Combo( app, options=Resolution_list, grid=[8,2], align='left') # BlueDot_button BlueDot_label = Text( app, text='BlueDot available', grid=[7,2], size=10, font='Helvetica', color='Blue', align='left' ) BlueDot_button = PushButton( app, command=BlueDot_control, text='BlueDot', grid=[8,3], align='left' ) # Check boxes HFlip_chkbox = CheckBox(app, text='Hflip', grid=[2,2], align="left") VFlip_chkbox = CheckBox(app, text='Vflip', grid=[2,3], align="left") # Sliders previewTime = Slider( app, start=previewTime_min, end=previewTime_max, grid=[7,1] ) # Contrast slider Contrast_label = Text( app, text='Contrast', grid=[3,2], size=10, font='Helvetica', color='Blue', align='left' ) Contrast = Slider( app, start=-100, end=100, grid=[3,3] ) # AWB gain slider AWBgains_label = Text( app, text='AWB gains (x10)', grid=[4,2], size=10, font='Helvetica', color='Blue', align='left' ) AWBgains = Slider( app, start=0, end=8*AWBgains_scale, grid=[4,3] ) # Brightness slider Brightness_label = Text( app, text='Brightness', grid=[5,2], size=10, font='Helvetica', color='Blue', align='left' ) Brightness = Slider( app, start=0, end=100, grid=[5,3] ) # Saturation slider Saturation_label = Text( app, text='Saturation', grid=[6,2], size=10, font='Helvetica', color='Blue', align='left' )
# Create a blank list to hold all the different screens all_screens = [] # Create a box to contain the menu buttons menu = Box(app, grid=[0,0], layout="grid") menu.tk.width = 900 menu.bg = "red" # Option 1 box option1 = Box(app, grid=[1,1]) text1 = Text(option1, text="This is the first page of stuff") combo = Combo(option1, options=["Beef", "Chicken", "Fish", "Vegetarian"]) all_screens.append(option1) # Option 2 box option2 = Box(app, grid=[1,1]) text2 = Text(option2, text="This is the second page of stuff") slider = Slider(option2) all_screens.append(option2) # Add the screens to the menu box option1_button = PushButton(menu, text="Option 1", command=switch_screen, args=[option1], grid=[0,0], align="left") option2_button = PushButton(menu, text="Option 2", command=switch_screen, args=[option2], grid=[1,0], align="left") # Hide all screens and then show the first one hide_all() all_screens[0].show() app.display()
20, top_text.value, color=color.value, size=40, font="courier") meme.text(20, 510, bottom_text.value, color="blue", size=size.value, font=font.value) app = App(title="meme", width=1210, height=745) top_text = TextBox(app, text="top text", command=draw_meme) bottom_text = TextBox(app, text="bottom text", command=draw_meme) color = Combo(app, options=["black", "white", "red", "green", "blue", "orange"], selected="orange", command=draw_meme) font = Combo(app, options=["times new roman", "courier", "verdana", "impact"], selected="times new roman", command=draw_meme) size = Slider(app, start=20, end=60, command=draw_meme) meme = Drawing(app, width="fill", height="fill") draw_meme() app.display()
from guizero import App, Text, TextBox, PushButton, Slider, Picture #displays value entered in the textbox def say_my_name(): welcome_message.value = my_name.value #defines what happens when the slider is moved def change_text_size(slider_value): welcome_message.size = slider_value app = App(title="Hello World") #adds a text widget welcome_message = Text(app, size=40, font="Ravie", color="lightblue") #adds a textbox widget my_name = TextBox(app, width=30) #adds a button widget update_text = PushButton(app, command=say_my_name, text="Display my name") #adds a slider widget text_size = Slider(app, command=change_text_size, start=10, end=80) #adds picture widget my_cat = Picture(app, image="coding_meme.gif") #creates the app app.display()
def launch_simulator(): global led_waffle global light_toggle global climate_dials button = [] if DEBUG: print("In launch_simulator function...") simulator = App(title='Physical Programming Simulator v2.0', layout='auto', bg='tan', height=600, width=420) # Setup LEDs - Only incoming from student program upper_box = Box(simulator, border=1, height=240, width=410) led_box = Box(upper_box, border=1, height=240, width=200, align='left') Text(led_box, text='Lights', width='fill') led_left_box = Box(led_box, height=240, width=100, align='left') Text(led_left_box, text='rled', align='top', size=27, color='red') Text(led_left_box, text='yled', align='top', size=27, color='yellow') Text(led_left_box, text='gled', align='top', size=27, color='green') Text(led_left_box, text='bled', align='top', size=27, color='blue') led_right_box = Box(led_box, height=240, width=100, align='right') led_waffle = Waffle(led_right_box, height=4, width=1, dim=40, color='black', dotty='True') # Setup Buttons - Only outgoing to student program and needs timeout value / function button_box = Box(upper_box, border=1, height=240, width=200, align='right') Text(button_box, text='Push Buttons', width='fill') for i in range(4): button.append( PushButton(button_box, height=1, width=6, padx=13, pady=11, text='Button_' + str(i + 1))) button[i].bg = 'gray' button[i].update_command(button_toggle, args=['Button_' + str(i + 1)]) Box(button_box, width=10, height=4) # Setup sliders for temperature in °F, humidity, and barometric pressure - Only outgoing to student program # Converted slider creation to use zip for parallel iteration in an effort to reduce code lower_box = Box(simulator, border=1, height=350, width=410) climate_box = Box(lower_box, border=1, height=350, width=200, align='left') Text(climate_box, text='Climate Statistics') Text(climate_box, text=' Temp °F Humidity Pressure', size=10) Text(climate_box, text=' temp humid press', size=10) # The following code creates three sliders for temperature, humidity and pressure using zip for parallel iteration for st, en, cmd in zip([150, 100, 31], [-50, 0, 29], [temperature_set, humidity_set, pressure_set]): Text(climate_box, width=1, align='left') climate_dials.append( Slider(climate_box, start=st, end=en, height=275, width=20, horizontal=False, align='left', command=cmd)) misc_box = Box(lower_box, border=1, height=350, width=200, align='right') misc_upper_box = Box(misc_box, border=1, height=170, width=200) Text(misc_upper_box, text='Light Sensor (light)') light_toggle = PushButton(misc_upper_box, image=night_image, height=130, width=175) misc_lower_box = Box(misc_box, border=1, height=170, width=200) Text(misc_lower_box, text='Obnoxious Buzzer (buzz)') Picture(misc_lower_box, image=here + 'Ouch.png', height=130, width=175) light_toggle.update_command(day_night_toggle, args=['light', light_toggle]) simulator.display()
servo1.angle = int(slider1_value) time.sleep(.25) def slider_change2(slider2_value): text2.value = slider2_value servo2 = AngularServo(Servo2, min_pulse_width=minpw, max_pulse_width=maxpw, initial_angle=0, min_angle=0, max_angle=180) servo2.angle = int(slider2_value) time.sleep(.25) if __name__ == '__main__': app = App() slider1 = Slider(app, start=0, end=180, width="fill", command=slider_change1) text1 = TextBox(app) slider2 = Slider(app, start=0, end=180, width='fill', command=slider_change2) text2 = TextBox(app) app.display()
def test_destroy(): a = App() s = Slider(a) destroy_test(s) a.destroy()