Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
tkinter python:如何从ttk.Entry中删除输入光标?_Python_Tkinter_Ttk - Fatal编程技术网

tkinter python:如何从ttk.Entry中删除输入光标?

tkinter python:如何从ttk.Entry中删除输入光标?,python,tkinter,ttk,Python,Tkinter,Ttk,我有一个ttk.Entry的实例。 用户点击它。 我把这件事订了。 根据某些条件,我要么希望输入光标出现并允许键入,要么基本上希望忽略单击而不让输入光标出现在ttk.Entry中。我不想使用只读或禁用状态 操纵焦点没有效果 这里有一门课,你问什么就做什么 class MyEntry(Entry): def disable(self): self.__old_insertontime = self.cget('insertontime') self.con

我有一个ttk.Entry的实例。 用户点击它。 我把这件事订了。 根据某些条件,我要么希望输入光标出现并允许键入,要么基本上希望忽略单击而不让输入光标出现在ttk.Entry中。我不想使用只读或禁用状态


操纵焦点没有效果

这里有一门课,你问什么就做什么

class MyEntry(Entry):

    def disable(self):
        self.__old_insertontime = self.cget('insertontime')
        self.config(insertontime=0)
        self.bind('<Key>', lambda e: 'break')

    def enable(self):
        self.unbind('<Key>')
        if self.cget('insertontime') == 0:
            self.config(insertontime=self.__old_insertontime)
然后像这样使用它:

class MyEntry(Entry):
    def __init__(self, *args, **kwds):
        Entry.__init__(self, *args, **kwds)
        self.config(disabledbackground=self.cget('background'))
        self.config(disabledforeground=self.cget('foreground'))
e = MyEntry(root)
e.config(state=DISABLED) # or state=NORMAL

注意。重新创建gui惯例时要小心。对用户来说,启用或禁用某些看起来像启用或禁用的内容可能会让人困惑。因此,除非你有充分的理由,否则不要更改它。

在浏览了ttk文档之后,这会起到以下作用:

    ttk.Style().map("TEntry",
                    foreground=[('disabled', 'black')],
                    fieldbackground=[('disabled','white')]
                    )
    widget['state'] = 'disabled'

为什么你不“想使用只读或禁用状态”?了解这一点可能有助于我们给出更好的答案。它们会改变小部件的外观,这对于我来说是不可接受的:(@sjjg:
Entry.config(state=DISABLED)
无需更改小部件的外观。只需通过“光标”设置
禁用背景
禁用背景
的颜色,以匹配
背景
放弃
,你是指用于指示插入位置的标记还是连接到鼠标的指针?@Donal:从上下文来看,我相信他指的是前者。我使用的是tkinter.ttk.Entry,而不是tkinter.Entry,所以解决方案并非如此。不过,你修改小部件的禁用状态是正确的-谢谢!我是investi屏蔽UI问题,因此能够处理它们是非常有用的。这在这里得到了很好的说明: