我正在使用Tkinter在python上构建一个计算器,并且我想使用我的计算器的屏幕键盘将数字始终添加到光标所在的位置(就像Ubuntu的计算器一样)。
我已经进行了很多搜索,但似乎找不到任何有关此问题的信息,除了tk.constant
INSERT
,它至少在我的使用方式上不起作用:
class MyClass
self.string = StringVar()
# trim...
def addChar(self, val):
string1=self.string.get()[:INSERT]
string2=self.string.get()[INSERT:]
self.string.set(string1 + val + string2)
要在Entry小部件的插入光标处插入字符或字符串,请使用insert
方法,以及索引"insert"
或tkinter常量INSERT
(我更喜欢前者):
self.e = tk.Entry(...)
...
self.e.insert("insert", "new text")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句