def pop_up_box(self, main_form): self.root = tk.Toplevel(master=main_form) self.root.title('') self.root.protocol('WM_DELETE_WINDOW', self.input_number) frame = tk.Frame(master=self.root) frame.grid(padx=8, pady=4) tk.Label(master=frame, text='How many beats per chord?' + '\n' + 'Please input a positive number.').grid(row=0, column=0) self.unit_entry = tk.Entry(master=frame, width=21, textvariable=tk.StringVar(frame, value='2')) self.unit_entry.grid(row=1, column=0) tk.Label(master=frame, text='How many beats in the first bar?' + '\n' + 'Please input a positive number.').grid(row=2, column=0) self.offset_entry = tk.Entry(master=frame, width=21, textvariable=tk.StringVar(frame, value='2')) self.offset_entry.grid(row=3, column=0) button = tk.Button(master=frame, text='OK', width=19, command=self.input_number) button.grid(row=4, column=0) self.main_ui.center_window(self.root) self.root.resizable(False, False) self.unit_entry.focus() self.root.mainloop() return
def add_filter(self, name, text, from_, to, column_index=0, column_span=1, show_switch=True): frame = self.frame self.scales[name] = tk.Scale(master=frame, length=150, resolution=1, from_=from_, to=to, orient=tk.VERTICAL) self.scales[name].bind('<ButtonRelease>', self.value_determined) self.scales[name].set(from_) self.scales[name].grid(row=1, column=column_index) self.labels[name] = tk.Label(master=frame, text=text, width=8, height=2) self.labels[name].grid(row=2, column=column_index) if show_switch == True: self.switch_vars[name] = tk.BooleanVar(master=frame, value=False) self.switches[name] = tk.Checkbutton( master=frame, variable=self.switch_vars[name], command=self.value_determined) self.switches[name].grid(row=3, column=column_index, columnspan=column_span)
def gui(self): self.root = tk.Tk() self.root.title('') self.root.protocol('WM_DELETE_WINDOW', self.quit_program) self.root.bind(sequence='<KeyPress>', func=self.key_press_event) self.root.bind(sequence='<KeyRelease>', func=self.key_release_event) # set pad frame = tk.Frame(master=self.root) frame.grid(padx=8, pady=16) # set title title_label = tk.Label(master=frame, font=('Arial', 20), text='Emotional Equalizer') title_label.grid(row=0, column=0, columnspan=5) tk.Label(master=frame, font=('Arial', 8)).grid(row=1, column=0, columnspan=5) # disable the equalizer interface # title_label.bind(sequence = '<ButtonRelease>', func = self.equalizer) # mood scales and labels mood_positions = [(2, 0), (2, 1), (2, 3), (2, 4), (5, 0), (5, 1), (5, 3), (5, 4)] for i in range(len(Mood.mood_strs)): self.mood_scales.append( tk.Scale(master=frame, length=150, resolution=1, from_=0, to=100, orient=tk.VERTICAL, showvalue=False, repeatinterval=1)) self.mood_scales[i].bind('<ButtonRelease>', self.value_determined) self.mood_scales[i].set(50) self.mood_scales[i].grid(row=mood_positions[i][0], column=mood_positions[i][1]) self.mood_labels.append( tk.Label(master=frame, font=('Arial', 15), height=2, width=15, text=Mood.mood_strs[i] + ': ' + str(100 - self.mood_scales[i].get()))) self.mood_labels[i].grid(row=mood_positions[i][0] + 1, column=mood_positions[i][1]) self.mood_scales[0]['command'] = lambda x: self.value_changed(event=0) self.mood_scales[1]['command'] = lambda x: self.value_changed(event=1) self.mood_scales[2]['command'] = lambda x: self.value_changed(event=2) self.mood_scales[3]['command'] = lambda x: self.value_changed(event=3) self.mood_scales[4]['command'] = lambda x: self.value_changed(event=4) self.mood_scales[5]['command'] = lambda x: self.value_changed(event=5) self.mood_scales[6]['command'] = lambda x: self.value_changed(event=6) self.mood_scales[7]['command'] = lambda x: self.value_changed(event=7) horizontal_line = tk.Label(master=frame, font=('Arial', 8), anchor=tk.N, height=2, text=' * ' * 20 + ' ' + ' * ' * 20) horizontal_line.grid(row=4, column=0, columnspan=5) vertical_line = tk.Label(master=frame, font=('Arial', 8), text='*\n' * 20 + '\n\n' + '*\n' * 20) vertical_line.grid(row=2, column=2, rowspan=5) # progress scale tk.Label(master=frame, font=('Arial', 8)).grid(row=7, column=0, columnspan=5) self.progress_scale = tk.Scale(master=frame, length=465, resolution=1, showvalue=True, orient=tk.HORIZONTAL, repeatinterval=1, state=tk.DISABLED) self.progress_scale.grid(row=8, column=0, columnspan=5) self.progress_scale.bind('<ButtonPress>', self.progress_scale_pressed) self.progress_scale.bind('<ButtonRelease>', self.progress_scale_released) tk.Label(master=frame, font=('Arial', 4)).grid(row=9, column=0, columnspan=5) # buttons button_width = 6 self.open_button = tk.Button(master=frame, text='Open', width=button_width, command=self.open_clicked) self.open_button.grid(row=10, column=0) self.play_pause_button = tk.Button(master=frame, text='Play', width=button_width, command=self.play_pause_clicked, state=tk.NORMAL) self.play_pause_button.grid(row=10, column=1) self.stop_button = tk.Button(master=frame, text='Stop', width=button_width, command=self.stop_clicked, state=tk.NORMAL) self.stop_button.grid(row=10, column=3) self.change_button = tk.Button(master=frame, text='Change', width=button_width, state=tk.NORMAL) self.change_button.bind('<Button-1>', self.change_clicked) self.change_button.bind('<Control-Button-1>', self.control_change_clicked) self.change_button.grid(row=10, column=4) tk.Label(master=frame, font=('Arial', 1)).grid(row=11, column=0, columnspan=5) self.reset_button = tk.Button(master=frame, text='Reset', width=button_width, command=self.reset) self.reset_button.grid(row=12, column=0) self.schedule_button = tk.Button(master=frame, text='Schedule', width=button_width, command=self.schedule) self.schedule_button.grid(row=12, column=1) speed_frame = tk.Frame(master=frame) speed_frame.grid(row=12, column=3, columnspan=2) self.tempo_label = tk.Label(master=speed_frame, font=('Arial', 15), text='Speed ') self.tempo_label.grid(row=0, column=0, columnspan=1) self.tempo_scale = tk.Scale(master=speed_frame, length=150, resolution=1, showvalue=False, orient=tk.HORIZONTAL, repeatinterval=1, from_=0, to=100) self.tempo_scale.set(50) self.tempo_scale.grid(row=0, column=1, columnspan=2) self.tempo_scale.bind('<ButtonRelease>', self.tempo_changed) # setting MainUI.center_window(self.root) self.root.resizable(False, False) self.root.focus() self.root.mainloop()
def main(): global check_button_vars, radio_button_var, all_excerpts, mood_records, quality_records global check_buttons, radio_buttons filenames = os.listdir( os.path.join(os.path.expanduser('~'), 'Desktop', 'Test', 'excerpts')) for filename in filenames: if filename.endswith('.wav'): all_excerpts.append(filename) mood_records[filename] = None quality_records[filename] = None shuffle(all_excerpts) root = tk.Tk() root.title('Listening Test') root.bind(sequence='<KeyPress>', func=key_press_event) frame = tk.Frame(master=root) frame.grid(padx=20, pady=10) question_label_1 = tk.Label(master=frame, text='What is the mood the music?', font=('Arial', 20)) question_label_1.grid(row=0, column=0, columnspan=4) question_label_2 = tk.Label(master=frame, text='(You can choose multiple moods)', font=('Arial', 16)) question_label_2.grid(row=1, column=0, columnspan=4) mood_strs = [ 'Angry', 'Scary', 'Comic', 'Happy', 'Sad', 'Mysterious', 'Romantic', 'Calm' ] for i in xrange(len(mood_strs)): mood = mood_strs[i] check_button_var = tk.IntVar(master=frame, value=0) check_button = tk.Checkbutton(master=frame, text=mood, variable=check_button_var) check_button.grid(row=2 + int(i / 4), column=i % 4) check_buttons.append(check_button) check_button_vars.append(check_button_var) tk.Label(master=frame, text='', font=('Arial', 4)).grid(row=4, column=0, columnspan=4) question_label_3 = tk.Label(master=frame, text='Does it sound musical?', font=('Arial', 20)) question_label_3.grid(row=5, column=0, columnspan=4) musical_frame = tk.Frame(master=frame) musical_frame.grid(row=6, column=0, columnspan=4) radio_button_text = [ 'Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree' ] radio_button_var.append(tk.IntVar(master=musical_frame, value=-1)) for i in xrange(5): radio_button = tk.Radiobutton(master=musical_frame, text=radio_button_text[i], variable=radio_button_var[0], value=i) radio_button.grid(row=0, column=i) radio_buttons.append(radio_button) repeat_button = tk.Button(master=frame, text='Repeat (Press R)', command=repeat_excerpt) repeat_button.grid(row=7, column=0, columnspan=2) next_button = tk.Button(master=frame, text='Next (Press Space)', command=next_excerpt) next_button.grid(row=7, column=2, columnspan=2) # setting center_window(root) root.resizable(False, False) root.focus() root.mainloop()
def pop_up_box(self, main_form, song_length): self.root = tk.Toplevel(master=main_form) self.root.protocol('WM_DELETE_WINDOW', self.back_to_main_ui) self.root.title('') # set pad frame = tk.Frame(master=self.root) frame.grid(padx=8, pady=8) # canvas self.canvas_offset = 3 self.canvas_width = 552 self.canvas_height = 492 self.canvas = tk.Canvas(master=frame, height=self.canvas_height, width=self.canvas_width) self.canvas.grid(row=0, column=0, columnspan=len(Mood.mood_strs)) self.canvas.bind('<B1-Motion>', self.canvas_clicked) self.canvas_resolution = 101 if self.main_ui.canvas_data != None: self.canvas_data = self.main_ui.canvas_data else: self.canvas_data = [] for i in xrange(self.canvas_resolution): self.canvas_data.append([]) for i in xrange(self.canvas_resolution): for j in xrange(self.canvas_resolution): self.canvas_data[i].append(0) self.main_ui.canvas_data = self.canvas_data # progress scale self.progress_scale = tk.Scale(master=frame, length=self.canvas_width, resolution=1, showvalue=True, orient=tk.HORIZONTAL, repeatinterval=1, state=tk.DISABLED) self.progress_scale['from'] = 0 if song_length != -1: self.progress_scale['to'] = song_length self.progress_scale['state'] = tk.NORMAL self.progress_scale.grid(row=1, column=0, columnspan=len(Mood.mood_strs)) self.progress_scale.bind('<ButtonPress>', self.progress_scale_pressed) self.progress_scale.bind('<ButtonRelease>', self.progress_scale_released) # radio buttons tk.Label(master=frame, font=('Arial', 1)).grid(row=2, column=0, columnspan=len(Mood.mood_strs)) label = tk.Label( master=frame, font=('Arial', 15), text= 'Please select the mood, and then you can draw the curve to describe its intensity' ) label.grid(row=3, column=0, columnspan=len(Mood.mood_strs)) index = 0 self.mood_color = [ 'yellow', 'magenta', 'orange', 'red', 'cyan', 'grey', 'pink', 'green' ] self.mood_index = tk.IntVar(master=frame, value=0) for mood in Mood.mood_strs: button = tk.Radiobutton(master=frame, text=mood, background=self.mood_color[index], variable=self.mood_index, value=index) button.grid(row=4, column=index) index += 1 # clear curve buttons tk.Label(master=frame, font=('Arial', 1)).grid(row=5, column=0, columnspan=8) clear_frame = tk.Frame(master=frame) clear_frame.grid(row=6, column=0, columnspan=len(Mood.mood_strs)) label = tk.Label(master=clear_frame, font=('Arial', 15), text='Clear the curves of') label.grid(row=0, column=0) clear_selected_mood = tk.Button(master=clear_frame, text='Selected', command=self.clear_selected_clicked) clear_selected_mood.grid(row=0, column=1) tk.Label(master=clear_frame, font=('Arial', 15), text='/').grid(row=0, column=2) clear_all_moods = tk.Button(master=clear_frame, text='All', command=self.clear_all_clicked) clear_all_moods.grid(row=0, column=3) tk.Label(master=clear_frame, font=('Arial', 15), text='moods from').grid(row=0, column=4) self.start_time_entry = tk.Entry(master=clear_frame, width=3, justify=tk.CENTER, textvariable=tk.StringVar(clear_frame, value='0')) self.start_time_entry.grid(row=0, column=5) tk.Label(master=clear_frame, font=('Arial', 15), text='% to').grid(row=0, column=6) self.end_time_entry = tk.Entry(master=clear_frame, width=3, justify=tk.CENTER, textvariable=tk.StringVar(clear_frame, value='100')) self.end_time_entry.grid(row=0, column=7) tk.Label(master=clear_frame, font=('Arial', 15), text='% of the song').grid(row=0, column=8) # redraw all curves self.clear(pow(2, 8) - 1) self.main_ui.center_window(self.root, 280, 0) self.root.resizable(False, False) self.root.focus()
def pop_up_box(self, main_form): self.root = tk.Toplevel(master=main_form) self.root.protocol('WM_DELETE_WINDOW', self.back_to_main_ui) self.root.title('') # set pad self.frame = tk.Frame(master=self.root) self.frame.grid(padx=8, pady=8) title_label = tk.Label(master=self.frame, font=('Arial', 20), text='Equalizer', height=2) title_label.grid(row=0, column=0, columnspan=14) self.scales = {} self.switch_vars = {} self.labels = {} self.switches = {} # low pass butterworth self.add_filter('LPB', 'Low Pass\nButterworth', 400, 20, column_index=0) # low pass shelving self.add_filter('LPS', 'Low Pass\nShelving', 1, 60, column_index=1) # low pass spectral tilt self.add_filter('LPT', 'Low Pass\nSepc Tilt', 1, 20, column_index=2) # high pass butterworth self.add_filter('HPB', 'High Pass\nButterworth', 1000, 20000, column_index=3) # high pass shelving self.add_filter('HPS', 'High Pass\nShelving', 1, 60, column_index=4) # high pass spectral tilt self.add_filter('HPT', 'High Pass\nSpec Tilt', 1, 20, column_index=5) # peak filter 1 self.add_filter('PK1', 'Peak 1\nCenter', 20, 100, column_index=6, column_span=2) self.add_filter('PK1-Width', 'Peak 1\nBand Width', 1, 100, column_index=7, show_switch=False) # peak filter 2 self.add_filter('PK2', 'Peak 2\nCenter', 100, 500, column_index=8, column_span=2) self.add_filter('PK2-Width', 'Peak 2\nBand Width', 5, 500, column_index=9, show_switch=False) # peak filter 3 self.add_filter('PK3', 'Peak 3\nCenter', 500, 2000, column_index=10, column_span=2) self.add_filter('PK3-Width', 'Peak 3\nBand Width', 20, 2000, column_index=11, show_switch=False) # peak filter 4 self.add_filter('PK4', 'Peak 4\nCenter', 2000, 20000, column_index=12, column_span=2) self.add_filter('PK4-Width', 'Peak 4\nBand Width', 100, 20000, column_index=13, show_switch=False) self.canvas = FigureCanvasTkAgg(self.fig, master=self.frame) self.canvas.get_tk_widget().grid(row=4, column=0, columnspan=14, ipady=40) self.root.resizable(False, False) self.root.focus() self.main_ui.center_window(self.root) self.value_determined()