使用TKinter进行def的替代

时间:2017-11-28 15:33:41

标签: python tkinter

我希望将一个从条目中获得的数字变为函数中的全局变量。这是我的代码:

argent1=120

def nom1():
global master, argent1, e11, g2
e1.config(state="disabled")
g1=Label(master,text=e1.get()).grid(row=2,column=0,sticky=W)
g2=Label(master,text=argent1).grid(row=2,column=1)
g3=Label(master,text="Mise de #1:").grid(row=4,column=0,sticky=W)
e11=Entry(master)
e11.grid(row=4,column=1)
e11.focus_set()
bou1=Button(master,text="Entrez",command=lambda:[devine1(),updatearg1()]).grid(row=4,column=2)

def updatearg1():
    global master, argent1, e11, g2
    g2.config(text=argent1-e11.get())

1 个答案:

答案 0 :(得分:0)

这应该很简单。这样的东西?

argent1=120
stringvar_name = tk.StringVar()


def nom1():
global master, argent1, e11, g2
e1.config(state="disabled")
g1=Label(master,text=e1.get()).grid(row=2,column=0,sticky=W)
g2=Label(master,text=argent1).grid(row=2,column=1)
g3=Label(master,text="Mise de #1:").grid(row=4,column=0,sticky=W)
e11=Entry(master, textvariable=stringvar_name)
e11.grid(row=4,column=1)
e11.focus_set()
bou1=Button(master,text="Entrez",command=lambda:[devine1(),updatearg1()]).grid(row=4,column=2)

def updatearg1():
    global master, argent1, e11, g2
    g2.config(text=argent1-e11.get())
    the_math_to_be_worked_out = stringvar_name - argent1