2

I'd like to print output value from spinbox, after clicking enter. I don't know why it is printing always value "from_" (so 1). What is the problem? Thank you.

import tkinter as tk
gui = tk.Tk()

gui.geometry("300x390")
gui.title("Test")

var = tk.IntVar()
tk.Spinbox(
    gui,
    textvariable=var,
    from_=1,
    to=10).pack()

a = var.get()

def print_test():
    print(a)


enter = tk.Button(gui, text="Enter", command=print_test).pack(pady=15)

gui.mainloop()
olenka
  • 43
  • 3
  • 3
    it is because u are storing the value of `var` in `a`, which is `1` at the time the line is executed. instead, move that line `a = var.get()` into the function `print_test()` and try.. – a_n Jun 25 '22 at 10:29

0 Answers0