python stringvar函数_Python函数意外返回PY_VAR1

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())

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页