[英]Tkinter Text Widget Indexing
I am building a simple calculator using Python and Tkinter. 我正在使用Python和Tkinter构建一个简单的计算器。 On this calculator am using the Text widget as the screen.I have buttons with numbers and symbols, which, when pressed, insert a character onto the screen.
在此计算器上,将文本小部件用作屏幕。我有带有数字和符号的按钮,按下这些按钮可在屏幕上插入一个字符。 The idea is that I take the contents of the screen as a string and pass them to eval().
这个想法是我将屏幕的内容作为字符串,并将它们传递给eval()。
How do I grab this contents of the screen? 如何获取屏幕上的内容? I've looked at indexing but it just doesn't seem to work.
我已经看过索引编制,但是它似乎没有用。
def buttonCommand(mytext, sym):
mytext.insert(END, sym)
if sym == "=":
return eval() #<-- something goes here?
def buttonCommand(mytext, sym):
mytext.insert(END, sym)
if sym == "=":
return eval(mytext.get())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.