|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 acid-lemon 于 2022-10-6 12:15 编辑
部分代码如下:
- def card_write():
- card_title = e2.get() #问题出在这句
- e1.insert(0, """<local:MyCard Title="%s">"""% card_title)
- def card(event):
- top = ttk.Toplevel()
- top.title("创建卡片")
- w = 500
- h = 307
- x = (root.winfo_screenwidth() - w) / 2
- y = (root.winfo_screenheight() - h) / 2
- top.geometry("%dx%d+%d+%d" % (w, h, x, y))
- L1 = ttk.Label(top, text="标题:", font = ("微软雅黑",13))
- e2 = ttk.Entry(top)
- b2 = ttk.Button(top, text="确定", command = card_write)
- b3 = ttk.Button(top,text = "取消", command = top.destroy)
- L1.place(width = 60, height = 30, x = 20, y = 15)
- e2.place(width = 400, height = 30, x = 70, y = 15)
- b2.place(width=60, height=30, x=100, y=200)
- b3.place(width=60, height=30, x=340, y=200)
复制代码
在父窗口按下按钮,打开子窗口,现在我想在父窗口读取e2的内容
但是e2是个局部变量,不能使用,求解决方法
那将 e2 设置声明为全局就行了吧
在 card 方法添加一行代码:global e2
|
|