0
import tkinter.ttk as ttk
from tkinter import *

root = Tk()
root.title("Nado")

lab_pro_val4 = Label(root)
lab_pro_val4 = Label(root, text='DD', width=30, height=1)
lab_pro_val4.pack()

ent_pro_val4 = Entry(root)
ent_pro_val4.pack()

def btncmd4_add():
    tru = ent_pro_val4.get() == 'TEST123'
    print(tru)

btn4_ppid = Button(root, text='Check', command=btncmd4_add(), bg='White')
btn4_ppid.pack()

root.mainloop()

I typed TEST123 but I got False not True — why not?
I think it's same. plz let me know... Which thing makes it wrong?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    Problem is `command=btncmd4_add()`. Don't call the function, just pass the function itself, i.e. `command=btncmd4_add`. Otherwise the function is executed once, before you typed anything, and the actual `command` is `None`. – tobias_k Jun 30 '22 at 15:22
  • `command=` and `root.bind()` and `root.after()` needs function's name without `()` - this commonly is called `callback` - and later `tkinter` will use `()` to execute it (ie. when you press button or use assigned key). The same can be in other languages. – furas Jun 30 '22 at 15:29

0 Answers0