Home > other >  After binding tkinter button click event, click get input box to the dynamic failure
After binding tkinter button click event, click get input box to the dynamic failure

Time:10-02

Beginners Python, encounter problems online search is not very good method, turn to the great god!!!!!!!!!!!!!!
Intention is such, there are a lot of function buttons, click a button, according to different input values, eventually get json parameters, then according to the change button corresponding color processing,

Wanted to directly use the command button, but can't find ways to get the corresponding button to change state,
Later can see binding events, but the button after binding event, the first interface initialization time obtaining input box is empty, if the input text, click the button again, seems will never pass into the text box values,

Any good solution, consult a great god

 
The import json
The from tkinter import *

Root=Tk ()

Def handler (event, * * data) :
Print (json. Dumps (data))
Print (event. The widget [' text '])

Def handlerAdap (handler1, * * d) :
Return the lambda event, handler2=handler1, data=https://bbs.csdn.net/topics/d: handler2 (event, * * data)

Frame=frame (root, width=200, height=200)
Frame. The pack ()

Var_name=StringVar ()
Entry (frame, width=16, textvariable=var_name). The grid (row=0, the column=0, sticky=W)
Var_value=(https://bbs.csdn.net/topics/StringVar)
Entry (frame, width=16, textvariable=var_value). The grid (row=0, the column=1, sticky=W)

BTN=Button (frame, the text="login")
BTN. The grid (row=0, the column=2)
BTN. Bind (" & lt; Button 1 & gt;" , handlerAdap (handler, name=var_name. The get (), val=var_value. The get ()))

Root. Mainloop ()

CodePudding user response:

The great god give some advice,,,,

CodePudding user response:

Knot, find a solution, can the adapter to skip, although is not very understand,,,
  • Related