python - 如何禁止在 Python/Tk 程序中选择文本?

标签 python user-interface text tkinter

那要怎么做呢? 我无法在此处或通过 Google 找到它。

#Refrences
from tkinter import *

class Interface:

    def __init__(self,stage):

        topLeft = Frame(stage,bg='black')
        test = Entry(topLeft,bg='#2a2a2a',fg='white',insertontime=0)
        test.config(insertbackground='white', exportselection=0)
        test.grid()
        topLeft.grid(row=0,column=0)

def launch():
    window = Tk()
    lobby = Interface(window)
    window.mainloop()

launch()

最佳答案

我假设您希望用户无法编辑输入框?如果是,则必须使用(state="disabled") 的配置参数,例如。

test.config(insertbackground='white', exportselection=0, state="disabled")

不过请注意,我找不到让您的输入框背景保持黑色的方法。希望这有帮助

关于python - 如何禁止在 Python/Tk 程序中选择文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26208695/

相关文章:

python - 寻找一种将复选框添加到列表列中的简单方法(wxPython)

Java:无法将字符串转换为数组

Java 相当于 python 嵌套 for 循环

python - 保存 matplotlib 动画会导致错误

python - 将 "#N/A"转换为 42 的 xlrd Excel 脚本

java - 在状态通知上放置按钮

python - 无法修改函数以独立工作而不是依赖于返回的结果

java - 在每个 ListView 项目中添加 Heavy UI

html - 输入打印时内部没有文本,但在屏幕上可见

text - 我可以让 Greasemonkey 脚本在文本文件上运行吗?