Python 在 Tkinter 中,如何禁用 Entry?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19876992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:51:42  来源:igfitidea点击:

In Tkinter, How I disable Entry?

pythonpython-3.xtkinter

提问by Emek K?rarslan

How I disable Entry in Tkinter.

我如何禁用 Tkinter 中的条目。

def com():
       ....

entryy=Entry()
entryy.pack()

button=Button(text="Enter!", command=com, font=(24))
button.pack(expand="yes", anchor="center")

As I said How I disable Entry in com function?

正如我所说,如何在 com 功能中禁用 Entry?

采纳答案by falsetru

Set stateto 'disabled'.

设置state'disabled'

For example:

例如:

from tkinter import *

root = Tk()
entry = Entry(root, state='disabled')
entry.pack()
root.mainloop()

or

或者

from tkinter import *

root = Tk()
entry = Entry(root)
entry.config(state='disabled') # OR entry['state'] = 'disabled'
entry.pack()
root.mainloop()

See Tkinter.Entry.config

Tkinter.Entry.config



So the comfunction should read as:

所以com函数应该读作:

def com():
    entry.config(state='disabled')

回答by Pakistan Beauty

if we want to change again and again data in entry box we will have to first convert into Normal state after changing data we will convert in to disable state

如果我们想一次又一次地更改输入框中的数据,我们必须在更改数据后首先转换为正常状态,我们将转换为禁用状态

import tkinter as tk
count = 0

def func(en):
    en.configure(state=tk.NORMAL)
    global count
    count += 1
    count=str(count)
    en.delete(0, tk.END)
    text = str(count)
    en.insert(0, text)
    en.configure(state=tk.DISABLED)
    count=int(count)


root = tk.Tk()

e = tk.Entry(root)
e.pack()

b = tk.Button(root, text='Click', command=lambda: func(e))
b.pack()

root.mainloop()