import tkinter as tk HEIGHT = 500 WIDTH = 600 def multiple(fund): ratio = [1.222223, 1.25, 1.33, 4.3, 1.23, 2.323] i = 0 for i in range (len(ratio)): nfreq = fund * (ratio[i]) print(f"{i} note is: " + str(round(nfreq, 3))) i += 1 scale= multiple(int(input("Enter a fund: "))) print(scale) root = tk.Tk() canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH) canvas.pack() frame = tk.Frame(root, bg='#80c1ff', bd=5) frame.place(relx=0.5, rely=0.3, relwidth=0.5, relheight=0.1, anchor='n') entry = tk.Entry(frame, font=40) entry.place(relwidth=0.65, relheight=1) button = tk.Button(frame, text="Get scale", font=40, command=lambda:multiple(entry.get())) button.place(relx=0.7, relheight=1, relwidth=0.3) root.mainloop()this is one try,
(Sep-20-2020, 06:48 PM)deanhystad Wrote: But as the name implies, I think this is a weird function. It is unusual for a function to contain "input" and "print" commands. Maybe this makes perfect sense in this case, but you mentioned using this in a gui interface and "input" and "print" don't work for those. I would be inclined to write this as a function that takes a frequency and returns a list of notes.
def weird_function(note): ratios = [1.0, 1.222223, 1.25, 1.33,4.3,1.23,2.323] return [note * ratio for ratio in ratios] freq = int(input("Enter a fundamental frequency: ")) print(*weird_function(freq))
Thanks for this. So I try to continue this method like that:
import tkinter as tk HEIGHT = 500 WIDTH = 600 def weird_function(note): ratios = [1.0, 1.222223, 1.25, 1.33, 4.3, 1.23, 2.323] return [note * ratio for ratio in ratios] freq = int(input("Enter a fundamental frequency: ")) print(*weird_function(freq)) root = tk.Tk() canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH) canvas.pack() #background_image = tk.PhotoImage(file='') #background_label = tk.Label(root,image=background_image) #background_label.place(relwidth=1,relheight=1) frame = tk.Frame(root, bg='#80c1ff', bd=5) frame.place(relx=0.5, rely=0.3, relwidth=0.5, relheight=0.1, anchor='n') entry = tk.Entry(frame, font=40) entry.place(relwidth=0.65, relheight=1) button = tk.Button(frame, text="Get scale", font=40, command=lambda:weird_function(entry.get())) button.place(relx=0.7, relheight=1, relwidth=0.3) root.mainloop()how can I run this program successfully so first thing that come up is the canvas and when I enter the frequency at the entry it will return the function weird_function.