日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python列表appendtext_python-默认文本以及列表textvariable Entry小部...

發布時間:2024/7/5 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python列表appendtext_python-默认文本以及列表textvariable Entry小部... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為了將默認文本放在Entry小部件中,可以使用here所述的insert()方法.

box.insert(0, "Value 1") # Set default text at cursor position 0.

現在,為了在用戶在框內單擊鼠標后更改框的內容,您需要將事件綁定到Entry對象.例如,以下代碼在單擊該框時將其刪除. (您可以閱讀有關事件和綁定here的信息.)在下面,我顯示了一個完整的示例.

請注意,刪除框中的文本可能僅對第一次單擊有效(即刪除默認內容時),因此我創建了一個單擊的全局標志以跟蹤是否已單擊它.

from tkinter import Tk, Entry, END # Python3. For Python2.x, import Tkinter.

# Use this as a flag to indicate if the box was clicked.

global clicked

clicked = False

# Delete the contents of the Entry widget. Use the flag

# so that this only happens the first time.

def callback(event):

global clicked

if (clicked == False):

box[0].delete(0, END) #

box[0].config(fg = "black") # Change the colour of the text here.

clicked = True

root = Tk()

box = [] # Declare a list for the Entry widgets.

box.append(Entry(fg = "gray")) # Create an Entry box with gray text.

box[0].bind("", callback) # Bind a mouse-click to the callback function.

box[0].insert(0, "Value 1") # Set default text at cursor position 0.

box.append(Entry(fg = "gray")) # Make a 2nd Entry; store a reference to it in box.

box[1].insert(0, "Value 2")

box[0].pack() #

box[1].pack()

if __name__ == "__main__":

root.mainloop()

總結

以上是生活随笔為你收集整理的python列表appendtext_python-默认文本以及列表textvariable Entry小部...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。