from tkinter import * # all the classic tkinter stuff from tkinter import ttk # some newer additional widgets """ Background Funktionen """ def button_rauschen_minus_press(): print("Rauschen_Press_Plus pressed") def button_rauschen_plus_press(): print("Rauschen Press_Minus pressed") # Ohr (links/beide/rechts) def button_linkes_ohr_press(): print("button linkes ohr pressed") def button_beide_ohren_press(): print("button beide ohren pressed") def button_rechtes_ohr_press(): print("button rechtes ohr pressed") # Lautstärke def scale_lautstärke_change(self): lautstärke = float(scaleLautstärke.get()) print(lautstärke) root = Tk() # build the main window root.title("Tinnitus Analyse") # MainFrame mainFrame = ttk.Frame(root, padding="3 3 30 30") # parent is root, padding is extra space at the edges mainFrame.grid(column=0, row=0, sticky=(N, W, E, S)) # the frame sticks to every side of the window when resized # Frequenz labelFrequenz = Label(mainFrame, text="Frequenz [kHz]") labelFrequenz.grid(row=0, column=0, sticky="w") # sticky = w(est) makes the text left aligned frequenz = StringVar() # Frequenz Variable [kHz] entryFrequenz = ttk.Entry(mainFrame, width=7, textvariable=frequenz) # create a field where u can enter text entryFrequenz.grid(column=1, row=0, sticky=(W, E)) # position the field # todo: Failproof the entry field to just numbers between a range! # todo: add function to entry change! # Rauschen labelRauschen = Label(mainFrame, text="Rauschen [+/- kHz]", anchor="w") labelRauschen.grid(column=0, row=1, sticky="w") buttonRauschenPlus = Button(mainFrame, text="+", command=button_rauschen_plus_press) buttonRauschenPlus.grid(column=1, row=1) buttonRauschenMinus = Button(mainFrame, text="-", command=button_rauschen_minus_press) buttonRauschenMinus.grid(column=2, row=1) rauschen = StringVar() # Rauschen Variable [+/- kHz] entryRauschen = ttk.Entry(mainFrame, width=7, textvariable=rauschen) # create a field where u can enter text entryRauschen.grid(column=3, row=1) # position the field # todo: add function to entry change # Linkes / Rechts Ohr labelOhren = Label(mainFrame, text="Audioausgabe auf:") labelOhren.grid(column=0, row=2, sticky="w") buttonLinkesOhr = Button(mainFrame, text="linkem Ohr", command=button_linkes_ohr_press) buttonLinkesOhr.grid(column=1, row=2) buttonBeideOhren = Button(mainFrame, text="beiden Ohren", command=button_beide_ohren_press) buttonBeideOhren.grid(column=2, row=2) buttonRechtesOhr = Button(mainFrame, text="rechtem Ohr", command=button_rechtes_ohr_press) buttonRechtesOhr.grid(column=3, row=2) # Lautstärke labelLautstärke = Label(mainFrame, text="Lautstärke [%]:") labelLautstärke.grid(column=0, row=3) scaleLautstärke = Scale(mainFrame, from_=0, to=100, orient=HORIZONTAL, length=200, command=scale_lautstärke_change) scaleLautstärke.grid(column=1, row=3, columnspan=2) # --------------EXAMPLE GUI---------------------- # mainframe = ttk.Frame(root, padding="3 3 3 3") # parent is root, padding is extra space at the edges # mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) # the frame sticks to every side of the window when resized # root.columnconfigure(0, weight=1) # if the main window is resized, the frame should expand to take up the extra space # root.rowconfigure(0, weight=1) # if the main window is resized, the frame should expand to take up the extra space # # frequency = StringVar() # a StringVar is meant to be used to edit Tkinter widget's texts # meters = StringVar() # # """ # Frequency Entry # """ # frequency_entry = ttk.Entry(mainframe, width=7, textvariable=frequency) # create a field where u can enter text # frequency_entry.grid(column=2, row=1, sticky=(W, E)) # position the field # ttk.Label(mainframe, text="Frequenz (kHz)").grid(column=1, row=1, sticky=W) # label the field # # """ # Rauschen # """ # frequency_entry = ttk.Entry(mainframe, width=7, textvariable=frequency) # create a field where u can enter text # frequency_entry.grid(column=2, row=1, sticky=(W, E)) # position the field # ttk.Label(mainframe, text="frequency (kHz)").grid(column=1, row=1, sticky=W) # label the field # # ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E)) # ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W) # # #ttk.Label(mainframe, text="frequency (kHz)").grid(column=3, row=1, sticky=W) # ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E) # ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W) # # for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5) # # frequency_entry.focus() # root.bind('', calculate) root.mainloop()