代码1:
import tkinter.filedialog from tkinter import * from tkinter import messagebox def OpenFile(): filename=filedialog.askopenfilename() messagebox.showinfo("温馨提示:",filename) w=Tk() w.title("打开文档测试") Button(w,text="打开文件",command=OpenFile).pack() w.mainloop()
代码2:
import tkinter.colorchooser from tkinter import * from tkinter import messagebox def OpenColor(): colorvalue=colorchooser.askcolor() messagebox.showinfo("温馨提示:",colorvalue) w=Tk() w.geometry("500x500") Button(w,text="选择颜色",command=OpenColor).pack() w.mainloop()