[英]How to open a file in the user's default program on button click with tkinter?
[英]How to make a file open by default with tkinter app?
我制作了一個用於顯示圖像的 tkinter 應用程序,我想知道是否有辦法使用此應用程序默認打開圖像目前如果我嘗試這樣做,我會收到一些未聲明的圖標文件的錯誤(這是圖標出現在頂部應用程序名稱附近)這個 Gui 沒有真正的目標,我只是在試驗和學習。
謝謝
嘗試這個:
from PIL import Image, ImageTk
import tkinter as tk
from tkinter import filedialog
my_img = []
def FileImport():
file = filedialog.askopenfilename()
my_img.clear()
my_img.append(ImageTk.PhotoImage(Image.open(file)))
label1.config(image=my_img[0])
root= tk.Tk()
root.title('Main')
root.geometry('400x400')
label = tk.Label(root, text = "Browse", fg="purple")
label.pack()
button = tk.Button(root, text='See Image',fg="blue", command=FileImport)
button.pack()
my_img.append(ImageTk.PhotoImage(Image.open(your_first_image)))
label1 = tk.Label(root, image = my_img[0])
label1.pack(pady= 50)
root.mainloop()
當你運行這個:
希望能幫助到你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.