Sep-22-2020, 11:43 AM
Hi,
I have this gui interface:
Can someone help with it ?
I have this gui interface:
#from tkinter import * import tkinter as tk root = tk.Tk() HEIGHT = 700 WIDTH = 600 canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH) canvas.pack() # background_image = tk.PhotoImage(file='/pupik.png') # 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: scale(entry.get())) button.place(relx=0.7, relheight=1, relwidth=0.3) lower_frame = tk.Frame(root, bg='#80c1ff', bd=10) lower_frame.place(relx=0.5, rely=0.5, relwidth=0.8, relheight=0.4, anchor='n') label = tk.Label(lower_frame) label.place(relwidth=1, relheight=1) root.mainloop()and this code that when you run it he ask you to enter a number(int or float) and it print a number of notes related to the number you entered.
import fractions
from tkinter import *
def read_scales(file_name):
read = open(file_name, 'r')
i = 0
data = []
for line in read:
data.append(line.strip())
name =(' '.join(data[:1]).replace("!",""))
ratios = data[6:]
description = (' '.join(data[2:3]))
num_note = (' '.join(data[3:4]))
return (name,ratios,description,num_note)
read.close()
new=(read_scales("arabic_bayati.txt"))
name = new[0]
ratios=new[1]
description=new[2]
note_n=new[3]
print(f"scale name is: {name}")
print(f"Scale description is: {description}")
print(f"Number of notes: {note_n}")
float_ratios =[float(str(float(fractions.Fraction(x)))) for x in ratios]
#print("dec_ratios: ",float_ratios)
def scale_frequency(note,ratios):
return [note * ratio for ratio in ratios]
scale = (scale_frequency(int(input("Enter a frequency number: ")),float_ratios))
i=0
while i < len(scale):
print(f"fundamental note is: {scale[0]} ")
for n in scale:
print(f"note number {i+2} is: " + str(n))
i += 1and finally here is the txt file that should be save as arabic_bayati.txt! arabic_bayati_and_bayati-shuri_on_d.scl ! Arabic Bayati and Bayati-Shuri (Karjighar) with perde dugah on D by Dr. Oz. 11 ! 55/49 11/9 49/40 147/110 77/48 3/2 25/14 165/98 11/6 90/49 441/220I try to understand how to make the connection between the code and the gui interface, so the user can enter a number in the entry widget, then click the "get scale" button widget and finally all the data that printed will appear in the lower frame.
Can someone help with it ?
