|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- from tkinter import *
- root=Tk()
- root.geometry("444x777")
- m=[{"a":"天津A","b":"pirate"},
- {"a":"天津B","b":"target"},
- {"a":"重庆A","b":"man"},
- {"a":"重庆B","b":"circle"}]
- def tj():
- tianjin=Toplevel(root)
- Button(tianjin,text="我是天津人",background="pink").pack()
- def cq():
- chongqing=Toplevel(root)
- Button(chongqing,text="我是重庆人",background="red").pack()
- def gyl():
- for i in range(len(m)) :
- n=Button(root,text=m[i]["a"],
- cursor=m[i]["b"])
- n.pack()
- if m[i]["a"] =="天津":
- n.config(command=tj)
- elif m[i]["a"] == "重庆":
- n.config(command=cq)
- else :
- n.config(command=root.destroy)
- gyl()
- mainloop()
复制代码
程序运行后,点击按钮【天津A】【天津B】后,应显示出【我是天津人】!
而点击按钮【重庆A】【重庆B】后,应显示出【我是重庆人】!
球最佳~
- def gyl():
- for i in range(len(m)) :
- n=Button(root,text=m[i]["a"],
- cursor=m[i]["b"])
- n.pack()
- if "天津" in m[i]["a"]:
- n.config(command=tj)
- elif "重庆" in m[i]["a"]:
- n.config(command=cq)
- else:
- n.config(command=root.destroy)
复制代码
|
|