簡體   English   中英

tkinter 從 label 發送文本到輸入框

[英]tkinter send text from the label to entry box

如何將label中的發送文本發送到輸入框,或者直接將圖片路徑發送到tkinter中的輸入框?

from tkinter import *

from PIL import ImageTk,Image

from tkinter import filedialog

root = Tk()

def open():

    root.filename = filedialog.askopenfilename(initialdir="/", title="Select A File",filetypes=(("jpg files", "*.jpg"), ("all files", "*.*")))

    my_label = Label(root, text=root.filename).pack()

    my_btn = Button(root, text="Open files", command=open).pack()

#entry box

txt2 = Entry(root)

txt2.place(x=10, y=45)

root.mainloop()

您的意思是在 label 中獲取文本並將文本插入到條目中嗎?
如果是,您可以在條目中創建一個StringVar()
例如像這樣:

from tkinter import *         #For python 3                
from Tkinter import *         #For python 2             

root = Tk()         
txt = StringVar()            

#For inserting text
txt.set("This is a label and an entry")         
 
label = Label(root, textvariable=txt).pack()         

entry = Entry(root, textvariable=txt).pack()         

root.mainloop()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM