小编lin*_*naa的帖子

Tkinter文本selection_get()错误

我目前正在使用Tkinter应用程序,该应用程序将TextWidget用作主窗口小部件。

当我尝试获取当前选择时,会引发错误,但我不知道为什么...

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "C:\Users\Lina\Documents\Programmation\VPE project.py", line 502, in rechercher
    texte=code_text.selection_get()
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 626, in selection_get
    return self.tk.call(('selection', 'get') + self._options(kw))
TclError: PRIMARY selection doesn't exist or form "STRING" not defined
Run Code Online (Sandbox Code Playgroud)

谢谢。

编辑:我知道为什么它不起作用,我绑定到Ctrl-F,但是它已经绑定在TextWidgets中(默认情况下,它做的和LeftArrow完全一样)。现在的问题是,我该如何摆脱呢?

python textbox tkinter

5
推荐指数
1
解决办法
3095
查看次数

Tkinter - 在TextWidget中设置当前选择

我正在寻找一种方法来设置Tkinter文本小部件中的当前选择.

我已经尝试设置它mark_set(),但它不起作用......

text_widget.mark_set("sel.first", 1.0)
text_widget.mark_set("sel.last",  END)
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这个问题?

python tkinter

4
推荐指数
1
解决办法
1115
查看次数

标签 统计

python ×2

tkinter ×2

textbox ×1