![](/img/trans.png)
[英]how can I calculate the percentage of 2 values an user entered using tkinter
[英]How can I highlight the pre-entered text in tkinter ENTRY so User can just type over ( without selecting, deleting)
noob 在这里尝试使用 tkinter 创建一个简单的条目,因此突出显示了预先输入的文本“在此处输入您的姓名”。 然后用户可以输入他们的名字(或者点击删除来删除内容......)是否有任何简单的参数/方法可以与 ENTRY 一起使用?
from tkinter import *
root = Tk()
lbl1 = Label ( root, text = "Let's Play together")
lbl2 = Label ( root, text = "What's your Name ? ")
lbl1.grid( row=0, column=0)
lbl2.grid (row=1, column=0)
nameplayer = Entry(root, width=25, )
nameplayer.insert(0,"Enter your name here ")
nameplayer.grid(row=2, column=0)
root.mainloop()
谢谢 !!
自动选择文本可以通过Entry.selection_range
来完成
class Focus(event):
nameplayer.selection_range(0, END)
nameplayer.bind("<FocusIn>", Focus)
当用户在 Entry Widget 中单击时,这将 select 所有文本。 希望这有效:)
我建议你写一个 function 并为你的Entry
创建一个占位符。 然后用户只需点击并写下他/她的名字。 无需删除前置文本,然后写入名称。
使用此 function click()
来定义提示或实际占位符:
from tkinter import *
root = Tk()
lbl1 = Label(root, text = "Let's Play together")
lbl2 = Label(root, text = "What's your Name?")
lbl1.grid(row=0, column=0)
lbl2.grid(row=1, column=0)
nameplayer = Entry(root, width=25, )
nameplayer.insert(0, 'Enter your name here')
nameplayer.grid(row=2, column=0)
def click(event):
nameplayer.configure(state=NORMAL)
nameplayer.delete(0, END)
nameplayer.unbind('<Button-1>', clicked)
clicked = nameplayer.bind('<Button-1>', click)
root.mainloop()
nameplayer.bind('<FocusIn>', lambda x: nameplayer.selection_range(0, END))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.