Python函数意外返回PY_VAR1 [英] Python function returns PY_VAR1 unexpectedly
本文介绍了Python函数意外返回PY_VAR1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我期待我的按钮函数根据Spinner UI元素的当前值打印一个数字( minutes_selected
),但变量始终为PY_VAR1:
从tkinter导入*
从tkinter导入ttk
def get_minutes():
全球minutes_selected
minutes_selected.get()
print(mintes_selected)
$ b root = Tk()
minutes_selected = StringVar()
minutes_spinbox = Spinbox(root,from_ = 1,to = 1440,textvariable = minutes_selected).pack()
是否存在一些基本的误解,关于如何从函数内部访问变量?解析方案
您需要使用 get
方法来获取变量的值。
更改此项:
print(mintes_selected)
至此:
print(minutes_selected.get())
I am expecting my button function to print a number (minutes_selected
) based on the current value of the Spinner UI element, but the variable is always PY_VAR1:
from tkinter import *
from tkinter import ttk
def get_minutes():
global minutes_selected
minutes_selected.get()
print(mintes_selected)
root = Tk()
minutes_selected = StringVar()
minutes_spinbox = Spinbox(root, from_ = 1, to = 1440, textvariable = minutes_selected).pack()
Is there some basic misunderstanding with regards to how variables can be access from within a function?
解决方案
You need to use the get
method to get the value of the variable.
Change this:
print(mintes_selected)
To this:
print(minutes_selected.get())
这篇关于Python函数意外返回PY_VAR1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文