Python中文
首页
教程
问答
标签
搜索
登录
注册
在python中将用户输入文本存储为变量
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>嗨,我希望能够将用户输入文本作为变量存储,以便在Python中的定义之外使用。但我似乎只能访问定义本身中的变量。有什么办法让它在外面方便使用吗?在</p> <pre><code>import tkinter #Quit Window when ESC Pressed def quit(event=None): window.destroy() def GetCountry(): global InputCountry InputCountry = UserInput.get() #Create Main Window window=tkinter.Tk() window.geometry("%dx%d+%d+%d" % (330, 80, 200, 150)) window.title("Select Country to Analyze") window.bind('<Escape>', quit) UserInput = tkinter.Entry(window) UserInput.pack() ButtonClick = tkinter.Button(window, text='Enter', command=GetCountry) ButtonClick.pack(side='bottom') print(InputCountry) window.mainloop() </code></pre> <p>当我试图调用GetCountry或InputCountry时,它表示它们没有定义</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>未定义变量InputCountry,因为它只存在于<em>def GetCountry():</em>indent块的作用域中。对于GetCountry,它是一个函数,因此您需要编写这个函数,它应该可以工作:</p> <pre><code>print(GetCountry()) </code></pre> <p>希望有帮助!在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何合并多个PDF文件?
6 回答
如何合并多个xarray数据变量及其坐标?
2 回答
如何合并多个列中具有重复值的行
9 回答
如何合并多个唯一id
10 回答
如何合并多个图纸并使用图纸名称的名称重命名列名?
4 回答
如何合并多个字典并添加同一个键的值?(Python)
7 回答
如何合并多个搜索结果文件(pkl)以将它们全部打印在一起?
3 回答
如何合并多个数据帧
1 回答
如何合并多个数据帧并使用Pandas为假人添加列?
3 回答
如何合并多个数据帧并按时间戳排序
1 回答
如何合并多个数据帧的列表并用另一个lis标记每列
5 回答
如何合并多个数据框中的列
1 回答
如何合并多个文件?
9 回答
如何合并多个查询集?
3 回答
如何合并多个绘图?
10 回答
如何合并多个词典
2 回答
如何合并多个输入数据集(数据帧)?
2 回答
如何合并多条记录中拆分的文本行
1 回答
如何合并多索引列datafram
4 回答
如何合并多级(即多索引)数据帧?
1 回答