Python Forum
Help with tkinter gui and functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with tkinter gui and functions
#1
Hi,
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 += 1
and 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/220
I 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 ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Redirecting all print statements from all functions inside a class to Tkinter Anan 1 138 Apr-24-2021, 08:57 AM
Last Post: ndc85430
  [Tkinter] tkinter issue with variables carrying over between functions PengEng 1 572 Apr-06-2020, 06:13 PM
Last Post: deanhystad
  Functions with Tkinter Reldaing 2 1,224 Jan-03-2020, 06:57 PM
Last Post: Reldaing
  def functions in tkinter Fureneshi 5 1,278 Dec-26-2019, 11:34 PM
Last Post: woooee
  Functions running before they should be - Python Tkinter logic error jhf2 2 670 Nov-23-2019, 03:45 PM
Last Post: jhf2
  Binding functions to Menus in tkinter?? Mocap 1 897 Jul-23-2019, 01:37 AM
Last Post: Larz60+
  Variable not sharing same value between two different functions Python 2.7 Tkinter albert 0 1,088 Aug-31-2018, 10:45 AM
Last Post: albert

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020