简体   繁体   English

设置StringVar()不设置变量内的字符串

[英]Setting StringVar() not setting string within variable

The following is the functional issue I'm dealing with. 以下是我要处理的功能性问题。 While this example doesn't do it, word is being set by a for loop, so I can't just set "dave" with a string. 尽管此示例没有执行此操作,但是单词是由for循环设置的,因此我不能仅使用字符串设置“ dave”。 However, if you run it, you can see that "word" is printing "smith" and "dave" is printing "PYVAR0." 但是,如果运行它,您会看到“ word”正在打印“ smith”,而“ dave”正在打印“ PYVAR0”。 How can I fix it so "dave" prints "smith"? 我该如何解决,以便“戴夫”打印“史密斯”?

from Tkinter import *
import ttk
root = Tk()
word = "smith"
print word
dave = StringVar()
dave.set(word)
print dave

You need to invoke dave.get : 您需要调用dave.get

print dave.get()

Doing so will return the string value contained in the StringVar . 这样做将返回StringVar包含的字符串值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM