执行此代码后,我收到错误win未找到从不同函数运行tkinter很重要,因为这是作业法典:import tkinter as tkfrom tkinter import *def zui(kaj,saj): zun=kaj kaj=kaj+"=tk.Tk()" exec(kaj) saj=zun+".title('"+saj+"')" exec(saj)def zabel(self,naj,iaj,oaj,baj,gaj,taj): spsp=self+"="+"Label("+naj+", text='"+iaj+"', bg='"+oaj+"', height="+gaj+", width="+taj+",fg='"+baj+"')" spsp=str(spsp) exec(spsp)def zosition(qak,iak,nak): sspp=qak+".grid(row="+iak+", column="+nak+")" exec(sspp)def zainzoop(tak): sft=tak+".mainloop()" exec(sft)zui("win","zahid app")zabel("label","win","hello world","white","black","4","10")zosition("win","1","1")zainzoop("win")追踪:Traceback (most recent call last): File "c:/PyProjects/Patient Data Entry/hello.py", line 20, in <module> zabel("label","win","hello world","white","black","4","10") File "c:/PyProjects/Patient Data Entry/hello.py", line 12, in zabel exec(spsp) File "<string>", line 1, in <module>NameError: name 'win' is not defined
1 回答
精慕HU
TA贡献1845条经验 获得超8个赞
这是使用 tkinter 的一种非常奇怪的方式,无论如何我该判断谁。 采取一个参数来做出声明。这是执行官的样子:exec()globals()global
exec(spsp,globals())
exec(sspp,globals())
exec(sft,globals())
最后,应该这样称呼:zosition()
zosition("label","1","1")
以防万一您对它通常的样子感到好奇:
import tkinter as tk
kaj = tk.Tk()
kaj.title('zahid app')
spsp = tk.Label(kaj,text='Hello World',bg='white',fg='black',height=4,width=10)
spsp.grid(row=1,column=1)
kaj.mainloop() #much easier right?
- 1 回答
- 0 关注
- 132 浏览
添加回答
举报
0/150
提交
取消