def generateNewBoard(self): if self.emojiShowBox != None: self.emojiShowBox.destroy() if self.emojiGuessBox != None: self.emojiGuessBox.destroy() self.emojiShowBox = Box(self, layout="grid") self.emojiGuessBox = Box(self, layout="grid") emojis_path = os.listdir("images") show_images = [] guess_images = [] # Get random images for both boxes for i in range(0, self.config["board_size"] - 1): show_images.append( "images/" + emojis_path.pop(random.randint(0, len(emojis_path) - 1))) guess_images.append( "images/" + emojis_path.pop(random.randint(0, len(emojis_path) - 1))) # Get image that is equal between both boxes rand_index = random.randint(0, len(emojis_path) - 1) self.same_image = "images/" + emojis_path[rand_index] show_images.append(self.same_image) guess_images.append(self.same_image) random.shuffle(show_images) random.shuffle(guess_images) board_size_rows = math.floor(math.sqrt(self.config["board_size"])) for i in range(0, self.config["board_size"]): x = i // board_size_rows y = i % board_size_rows picture = Picture(self.emojiShowBox, grid=[x, y], image=show_images[i]) pushButton = PushButton(self.emojiGuessBox, grid=[x, y], image=guess_images[i]) pushButton.update_command(command=self.is_correct_guess, args=[pushButton])
def test_update_command_with_args(): a = App() callback_event = Event() def callback(value): assert value == "foo" callback_event.set() b = PushButton(a) b.update_command(callback, ["foo"]) b.tk.invoke() assert callback_event.is_set() a.destroy()
def spin_up_main_buttons(parent, commands): global buttons_box buttons_box = Box(parent, width='fill', height='fill', layout='auto') scan_in_button = PushButton(buttons_box, text='SCAN IN', height='fill', width='fill') scan_in_button.font = display_config.text_font scan_in_button.text_color = '#00FF21' scan_in_button.text_size = display_config.button_text_size scan_in_button.update_command(commands[0]) scan_out_button = PushButton(buttons_box, text='SCAN OUT', height='fill', width='fill') scan_out_button.font = display_config.text_font scan_out_button.text_color = '#B60000' scan_out_button.text_size = display_config.button_text_size scan_out_button.update_command(commands[1]) look_up_button = PushButton(buttons_box, text='LOOKUP', height='fill', width='fill') look_up_button.font = display_config.text_font look_up_button.text_color = '#FFD800' look_up_button.text_size = display_config.button_text_size look_up_button.update_command(commands[2])
def test_update_command(): a = App() callback_event = Event() def callback(): callback_event.set() b = PushButton(a) b.tk.invoke() assert not callback_event.is_set() b.update_command(callback) b.tk.invoke() assert callback_event.is_set() callback_event.clear() b.update_command(None) b.tk.invoke() assert not callback_event.is_set() a.destroy()
def analyze(): ldict = {} result = [] rdict.clear() term_dict.clear() if (len(btn_list) > 0): for btn in btn_list: btn.destroy() btn_list.clear() if (len(lbox_list) > 0): for lbox in lbox_list: lbox.destroy() lbox_list.clear() with open('conditions.csv', newline='') as f: reader = csv.reader(f) data = list(reader) for line in data: #line[1] = line[1].replace(" ","") ldict[line[0]] = line[1:][0].split(',') data = text_box.value data_lower = data.lower() tokenizer = nltk.data.load('tokenizers/punkt/english.pickle') if (preprocess_checkbox.value == 0): remove_history = re.sub('past medical history: diagnosis.*?drug use', ' drug use ', data_lower, flags=re.DOTALL) remove_physicala = re.sub('physical exam.*?assessment/plan', '. ASSESSMENT', remove_history, flags=re.DOTALL) remove_complete = re.sub('physical exam.*?assessment and plan', '. ASSESSMENT', remove_physicala, flags=re.DOTALL) sentence_list = tokenizer.tokenize(remove_complete) else: sentence_list = tokenizer.tokenize(data_lower) for sentence in sentence_list: for (key, terms) in ldict.items(): for term in terms: fixed_word = term.lower() # If have a special date character $date$ # Insert the found dates into the ldict array as a term if fixed_word == "$date$": ldict[key].extend(date_match) continue if fixed_word in sentence: dup_check = [key, sentence] # If a sub term comes up we save it if (sentence, key) in term_dict: term_dict[(sentence, key)].append(fixed_word) else: term_dict[(sentence, key)] = [fixed_word] if dup_check not in result: result.append([key, sentence]) if key in rdict: rdict[key].append(sentence) else: rdict[key] = [sentence] lbox_list.append( ListBox(form_box, items=sentence_list, width="fill", height=resolution[rt]['lbox_height'], command=dispay_full, multiselect=True, scrollbar=True)) lbox_list[0].bg = "#C8D7E9" counter = 0 btn = "" for (k, vl) in ldict.items(): if (counter < 4): if k in rdict: if (platform != 'win32'): btn = PushButton(button_box_r1, align="left", width="10", text=str("█" + k), command=pval, pady=resolution[rt]['button_pady']) else: btn = PushButton(button_box_r1, align="left", width="10", text=k, command=pval, pady=resolution[rt]['button_pady']) btn.update_command(pval, [k, lbox_list[0]]) btn.bg = "#9EF844" else: btn = PushButton(button_box_r1, align="left", width="10", text=k, pady=resolution[rt]['button_pady']) btn.bg = "#F84446" elif (counter < 8): if k in rdict: if (platform != 'win32'): btn = PushButton(button_box_r2, align="left", width="10", text=str("█" + k), command=pval, pady=resolution[rt]['button_pady']) else: btn = PushButton(button_box_r2, align="left", width="10", text=k, command=pval, pady=resolution[rt]['button_pady']) btn.update_command(pval, [k, lbox_list[0]]) btn.bg = "#9EF844" else: btn = PushButton(button_box_r2, align="left", width="10", text=k, pady=resolution[rt]['button_pady']) btn.bg = "#F84446" elif (counter < 12): if k in rdict: if (platform != 'win32'): btn = PushButton(button_box_r3, align="left", width="10", text=str("█" + k), command=pval, pady=resolution[rt]['button_pady']) else: btn = PushButton(button_box_r3, align="left", width="10", text=k, command=pval, pady=resolution[rt]['button_pady']) btn.update_command(pval, [k, lbox_list[0]]) btn.bg = "#9EF844" else: btn = PushButton(button_box_r3, align="left", width="10", text=k, pady=resolution[rt]['button_pady']) btn.bg = "#F84446" elif (counter < 16): if k in rdict: if (platform != 'win32'): btn = PushButton(button_box_r4, align="left", width="10", text=str("█" + k), command=pval, pady=resolution[rt]['button_pady']) else: btn = PushButton(button_box_r4, align="left", width="10", text=k, command=pval, pady=resolution[rt]['button_pady']) btn.update_command(pval, [k, lbox_list[0]]) btn.bg = "#9EF844" else: btn = PushButton(button_box_r4, align="left", width="10", text=k, pady=resolution[rt]['button_pady']) btn.bg = "#F84446" elif (counter < 20): if k in rdict: if (platform != 'win32'): btn = PushButton(button_box_r5, align="left", width="10", text=str("█" + k), command=pval, pady=resolution[rt]['button_pady']) else: btn = PushButton(button_box_r5, align="left", width="10", text=k, command=pval, pady=resolution[rt]['button_pady']) btn.update_command(pval, [k, lbox_list[0]]) btn.bg = "#9EF844" else: btn = PushButton(button_box_r5, align="left", width="10", text=k, pady=resolution[rt]['button_pady']) btn.bg = "#F84446" elif (counter < 24): if k in rdict: if (platform != 'win32'): btn = PushButton(button_box_r6, align="left", width="10", text=str("█" + k), command=pval, pady=resolution[rt]['button_pady']) else: btn = PushButton(button_box_r6, align="left", width="10", text=k, command=pval, pady=resolution[rt]['button_pady']) btn.update_command(pval, [k, lbox_list[0]]) btn.bg = "#9EF844" else: btn = PushButton(button_box_r6, align="left", width="10", text=k, pady=resolution[rt]['button_pady']) btn.bg = "#F84446" elif (counter < 28): if k in rdict: if (platform != 'win32'): btn = PushButton(button_box_r7, align="left", width="10", text=str("█" + k), command=pval, pady=resolution[rt]['button_pady']) else: btn = PushButton(button_box_r7, align="left", width="10", text=k, command=pval, pady=resolution[rt]['button_pady']) btn.update_command(pval, [k, lbox_list[0]]) btn.bg = "#9EF844" else: btn = PushButton(button_box_r7, align="left", width="10", text=k, pady=resolution[rt]['button_pady']) btn.bg = "#F84446" elif (counter < 32): if k in rdict: if (platform != 'win32'): btn = PushButton(button_box_r8, align="left", width="10", text=str("█" + k), command=pval, pady=resolution[rt]['button_pady']) else: btn = PushButton(button_box_r8, align="left", width="10", text=k, command=pval, pady=resolution[rt]['button_pady']) btn.update_command(pval, [k, lbox_list[0]]) btn.bg = "#9EF844" else: btn = PushButton(button_box_r8, align="left", width="10", text=k, pady=resolution[rt]['button_pady']) btn.bg = "#F84446" counter += 1 btn_list.append(btn)
# Admin row 2 adbox = Box(admin_tab, grid=[1, 1]) aebox = Box(admin_tab, grid=[2, 1]) afbox = Box(admin_tab, grid=[3, 1]) # This section has the GUI widgets in the cbox area # Loop through the course_list and create a button for each one for course in course_list: course_btn = PushButton(cbox, text=course.get_cname(), width=10, height=3) course_btn.bg = (129, 217, 222) course_btn.text_color = (255, 255, 255) course_btn.update_command(food_details, [course.get_cname()]) admin_button = PushButton(cbox, text="Admin", command=admin_access, width=10, height=3) admin_button.bg = (129, 217, 222) admin_button.text_color = (255, 255, 255) food_listbox = ListBox(fbox) food_listbox.update_command(add_food) order_listbox = ListBox(obox, width=200, height=200) delete_button = PushButton(obox, text="Undo", command=undo) clear_button = PushButton(obox, text="Clear", command=clear_order) finish_button = PushButton(obox, text="Finish", command=finish_order)
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()
generate_students() # create the application interface app = App(title="Student management system", layout="grid") # This is section where you add any GUI widgets # Loop through the teacher_list and create a button for each one row = 0 column = 0 for teacher in teacher_list: if column == 3: column = 0 row += 1 else: teacher_btn = PushButton(app, text=teacher.get_tname(), width=10, height=3, grid=[column, row]) teacher_btn.update_command(teacher_details, [teacher.get_tname()]) column += 1 teacher_label = Text(app, grid=[0, row + 1]) class_label = Text(app, grid=[0, row + 2]) class_listbox = ListBox(app, grid=[0, row + 3]) class_count_label = Text(app, grid=[0, row + 4]) # Start the program app.display()
def start(): print('start') global timelimit sleep(0.5) button.hide() box = Box(app, width=800, height=80, grid=[0, 1], layout="grid") box.border = 1 bapp = Box(app, width=790, height=100, layout="grid", grid=[0, 2]) bapp.border = 1 questionone = Text(app, text="What day is it today?", grid=[0, 0]) questionone.text_size = 40 monday = PushButton(bapp, grid=[0, 2], command=checkday, height=2, width=9, text="Monday") monday.text_size = 21 monday.bg = 'red' monday.update_command(checkday, args='0') tuesday = PushButton(bapp, grid=[1, 2], command=checkday, height=2, width=9, text="Tuesday") tuesday.text_size = 21 tuesday.bg = 'orange' tuesday.update_command(checkday, args='1') wednesday = PushButton(bapp, grid=[2, 2], command=checkday, height=2, width=9, text="Wednesday") wednesday.text_size = 21 wednesday.bg = 'yellow' wednesday.update_command(checkday, args='2') thursday = PushButton(bapp, grid=[3, 2], command=checkday, height=2, width=9, text="Thursday") thursday.text_size = 21 thursday.bg = 'green' thursday.update_command(checkday, args='3') friday = PushButton(bapp, grid=[0, 3], command=checkday, height=2, width=9, text="Friday") friday.text_size = 21 friday.bg = 'brown' friday.update_command(checkday, args='4') saturday = PushButton(bapp, grid=[1, 3], command=checkday, height=2, width=9, text="Saturday") saturday.text_size = 21 saturday.bg = 'grey' saturday.update_command(checkday, args='5') sunday = PushButton(bapp, grid=[2, 3], command=checkday, height=2, width=9, text="Sunday") sunday.text_size = 21 sunday.bg = 'purple' sunday.update_command(checkday, args='6') dunno = PushButton(bapp, grid=[3, 3], command=checkday, height=2, width=9, text='Dunno?') dunno.text_size = 21 dunno.bg = 'blue' dunno.update_command(checkday, args='7') app.update() timelimit = time()
def questiontwo(): global timelimit qt = Window(app, layout="grid", title="Question Two", width=800, height=400) qt.show() print("start question 2") f1 = Box(qt, width=100, height=400, grid=[0, 1]) f1.border = 1 f1.bg = "black" f2 = Box(qt, width=100, height=400, grid=[1, 1]) f2.border = 1 f2.bg = "black" f3 = Box(qt, width=100, height=400, grid=[3, 1]) f3.border = 1 f3.bg = "black" f4 = Box(qt, width=100, height=400, grid=[4, 1]) f4.border = 1 f4.bg = "black" f5 = Box(qt, width=100, height=400, grid=[5, 1]) f5.border = 1 f5.bg = "black" f6 = Box(qt, width=100, height=400, grid=[6, 1]) f6.border = 1 f6.bg = "black" f7 = Box(qt, width=100, height=400, grid=[7, 1]) f7.border = 1 f7.bg = "black" f8 = Box(qt, width=100, height=400, grid=[8, 1]) f8.border = 1 f8.bg = "black" bl = [f1, f3, f5, f7] x = 0 for i in range(1, randint(1, 4)): bl[i - 1].bg = "yellow" x = i print(x) qt.update() sleep(7.35478205493597) f1.visible = False f2.visible = False f3.visible = False f4.visible = False f5.visible = False f6.visible = False f7.visible = False f8.visible = False bo2 = Box(qt, width=800, height=80, grid=[0, 1], layout="grid") bo2.border = 1 b2pp = Box(qt, width=790, height=100, layout="grid", grid=[0, 2]) b2pp.border = 1 questiotwo = Text(qt, text="How many yellow lines were there?", grid=[0, 0]) questiotwo.text_size = 38 answer1 = PushButton(b2pp, grid=[0, 2], command=checknumber, height=2, width=9, text="One") answer1.text_size = 21 answer1.bg = 'red' answer1.update_command(checknumber, args=['1', x]) answer2 = PushButton(b2pp, grid=[1, 2], command=checknumber, height=2, width=9, text="Two") answer2.text_size = 21 answer2.bg = 'orange' answer2.update_command(checknumber, args=['2', x]) answer3 = PushButton(b2pp, grid=[2, 2], command=checknumber, height=2, width=9, text="Three") answer3.text_size = 21 answer3.bg = 'yellow' answer3.update_command(checknumber, args=['3', x]) answer4 = PushButton(b2pp, grid=[3, 2], command=checknumber, height=2, width=9, text="Four") answer4.text_size = 21 answer4.bg = 'green' answer4.update_command(checknumber, args=['4', x]) answer5 = PushButton(b2pp, grid=[0, 3], command=checknumber, height=2, width=9, text="Five") answer5.text_size = 21 answer5.bg = 'brown' answer5.update_command(checknumber, args=['5', x]) answer6 = PushButton(b2pp, grid=[1, 3], command=checknumber, height=2, width=9, text="Six") answer6.text_size = 21 answer6.bg = 'grey' answer6.update_command(checknumber, args=['6', x]) answer7 = PushButton(b2pp, grid=[2, 3], command=checknumber, height=2, width=9, text="Zero") answer7.text_size = 21 answer7.bg = 'purple' answer7.update_command(checknumber, args=['0', x]) answer8 = PushButton(b2pp, grid=[3, 3], command=checknumber, height=2, width=9, text="Dunno") answer8.text_size = 21 answer8.bg = 'blue' answer8.update_command(checknumber, args=['7', x]) timelimit = time()
def setup_gui(self): """ Bike Info """ d_description = Text(self.app, text="Diameter (mm): ", grid=[0, 1], align="left") input_diameter = TextBox(self.app, grid=[1, 1], width=10, align="left") m_description = Text(self.app, text="Bike Mass (kg): ", grid=[0, 2], align="left") input_mass = TextBox(self.app, grid=[1, 2], width=10, align="left") """ Horsepower """ h_description = Text(self.app, text="Horsepower (hp): ", grid=[0, 3], align="left") input_horsepower = TextBox(self.app, grid=[1, 3], width=10, align="left") """ Tachometer """ r_description = Text(self.app, text="Reading Amounts: ", grid=[0, 4], align="left") input_readings = TextBox(self.app, grid=[1, 4], width=10, align="left") degree = Text(self.app, text="Degree of inclination: ", grid=[0, 5], align="left") input_degree = TextBox(self.app, grid=[1, 5], width=10, align="left") incline = ButtonGroup(self.app, grid=[1, 6], options=["Uphill", "Level Ground", "Downhill"], selected="Uphill", align="left") update_everything = PushButton(self.app, command=self.updateE, text="Update Values", grid=[0, 7]) update_everything.update_command(command=self.updateE, args=[ input_diameter, input_horsepower, input_readings, input_mass ]) show_info = PushButton(self.app, command=self.displayValues, text="Calculate Results", grid=[1, 7], align="left") ### starts and stops tacho start_tacho = PushButton(self.app, command=self.mydyno.run_tacho, text="Start Readings", grid=[1, 10]) """ grapphing stuff """ show_graph = PushButton(self.app, command=self.mydyno.graphSpeed, text="Display Graph", grid=[1, 11]) """ Controller GUI """ show_controllergui = PushButton(self.app, command=self.display_controller, text="Display Motor Controller", grid=[2, 3]) self.app.display()