Textvariable error on Python tkinter module Label...

Asked 2 years ago, Updated 2 years ago, 97 views

import tkinter

window=tkinter.Tk() window.title("Composing Program") window.geometry("700x700+0+0") window.resizable(False, False)

o=4 def octaveDown(): global o o-=1 def octaveUp(): global o o+=1

down=tkinter.Button(window, text="<", command=octaveDown) octave=tkinter.Label(window, textvariable=int(o), bg="white") up=tkinter.Button(window, text=">", command=octaveUp)

down.place(x=425, y=30) octave.place(x=450, y=33) up.place(x=469, y=30)

Mark the octave label with an initial value of 4 If I press the up button, I want to add 1 and if I press the down button, I want to subtract 1. I tried to put Python's novice in it, but it didn't work. The white label is displayed, but the value corresponding to the variable you put in the text variable does not appear. Help me...

Additionally, depending on the value displayed in the label, I'm planning to change the sound frequency from the button to add more.

python tkinter

2022-09-21 18:18

1 Answers

Hello :-)

I know what you want to do. But if you put at least a few characters of python in the code that is hard to recognize and doesn't contain any formatting... That's too bad. T_T

You want to do it like this, right?

import tkinter

window=tkinter.Tk()
window.title("Composing Program")
window.geometry("700x700+0+0")
window.resizable(False, False)

o=4
def octaveDown():  
    global o; o-=1
    octave['text'] = o # Added here.
    octave.place(x=450, y=33)
def octaveUp():
    global o; o+=1
    octave['text'] = o # Added here.
    octave.place(x=450, y=33)

down=tkinter.Button(window, text="<", command=octaveDown)
octave=tkinter.Label(window, text=int(o), bg="white")
up=tkinter.Button(window, text=">", command=octaveUp)

down.place(x=425, y=30)
octave.place(x=450, y=33)
up.place(x=469, y=30)

window.mainloop() # You left this out.

CtrlC+CtrlV, put it in IDLE, and press F5 to find out.

Of course, it's a code that goes as you want. It doesn't look good. I want you to study the rest for yourself.

Thank you.


2022-09-21 18:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.