Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Hearing frequency sound tester v1.0
- By Steve Shambles 2018. Updated Nov 2019.
- Requirements: Windows only. No dependencies.
- More code atrocities at:
- stevepython.wordpress.com
- """
- from tkinter import Button, IntVar, Label, LabelFrame, Menu, messagebox
- from tkinter import Spinbox, TclError, Tk
- import webbrowser
- import winsound
- def help_info():
- """Help and offer info on hearing ranges at a website"""
- ask_yn = messagebox.askyesno('Help', 'A typical healthy adults hearing'
- ' is from 15hz to 20,000hz.\n\nI have Tinnitus and can only hear up to'
- ' 6000hz.\n\n Conversley, my healthy younger sister can hear 21000hz.\n\n'
- 'For more info: https://hypertextbook.com/facts/2003/ChrisDAmbrose.shtml'
- '\n\nClick YES to visit site, or NO to continue.')
- if ask_yn is True:
- webbrowser.open('https://hypertextbook.com/facts/2003/ChrisDAmbrose.shtml')
- else:
- return
- def about_menu():
- """Display program info message box"""
- messagebox.showinfo('About', 'Hearing Frequency Sound Tester V1.00'
- '\nFreeware by Steve Shambles 2018/2019')
- def visit_blog():
- """Visit my blog, you know it makes sense."""
- webbrowser.open('https://stevepython.wordpress.com/2018/08/29/hearing-frequency-tester')
- def hear_sound():
- """Play the sound at hz frequency for duration."""
- # If input is invalid, eg.non-numeric, then return
- try:
- dur = VAR.get()
- freq = VAR2.get()
- except TclError:
- messagebox.showerror('Error', 'Bad input error, Numbers only please.')
- return
- winsound.Beep(freq, dur)
- def hfst_info():
- """Reset spinboxes to default settings."""
- VAR.set(3000)
- VAR2.set(10000)
- # The GUI.
- root = Tk()
- root.title('HFST V1.00')
- root.geometry('266x165')
- root.resizable(False, False)
- main_frame = LabelFrame(root, text="Choose help from menu.")
- main_frame.grid(padx=20, column=0, row=0)
- # Create the drop down menu.
- menu_bar = Menu(root)
- file_menu = Menu(menu_bar, tearoff=0)
- menu_bar.add_cascade(label='Menu', menu=file_menu)
- file_menu.add_command(label='Help', command=help_info)
- file_menu.add_command(label='About', command=about_menu)
- file_menu.add_separator()
- file_menu.add_command(label='Visit my blog', command=visit_blog)
- file_menu.add_command(label='Exit', command=root.destroy)
- root.config(menu=menu_bar)
- # Create frame for duration label.
- drtn_frame = Label(main_frame)
- drtn_frame.grid(column=0, row=0)
- # Create drtn_label.
- drtn_label = Label(drtn_frame, fg='blue',
- text='Duration Msecs', font=('tahoma', '10', 'bold'))
- drtn_label.grid(padx=8, pady=8) # label wont appear without this line
- # frqncy_frame for frqncy_label.
- frqncy_frame = Label(main_frame)
- frqncy_frame.grid(column=0, row=1)
- # frqncy_label.
- frqncy_label = Label(frqncy_frame, fg='blue', text='Frequency Hz',
- font=('tahoma', '10', 'bold'))
- frqncy_label.grid()
- drtn_spinbox = Label(main_frame)
- drtn_spinbox.grid(column=1, row=0)
- VAR = IntVar()
- VAR.set(3000) # Default start value.
- sbox_drtn_widget = Spinbox(drtn_spinbox, from_=500, to=23000,
- width=4, increment=1000, textvariable=VAR)
- sbox_drtn_widget.grid()
- frq_spinbox = Label(main_frame)
- frq_spinbox.grid(column=1, row=1)
- VAR2 = IntVar()
- VAR2.set(10000) # Default start value.
- sbox_frq_widget = Spinbox(frq_spinbox, from_=37, to=23000, width=5,
- increment=100, textvariable=VAR2)
- sbox_frq_widget.grid()
- # hear_frame for hear button.
- hear_frame = Label(main_frame)
- hear_frame.grid(row=2, column=0)
- # Create the 'Hear' button.
- hear_btn = Button(hear_frame, bg='green2', text='Hear', command=hear_sound)
- hear_btn.grid(padx=8, pady=8)
- # Reset_frame for reset button.
- reset_frame = Label(main_frame)
- reset_frame.grid(row=2, column=1)
- # Create the reset button.
- hear_btn = Button(reset_frame, bg='red', text='Reset', command=hfst_info)
- hear_btn.grid(padx=8, pady=8)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement