暮色呼如
这是我用 tkinter 制作的,不是完美的消息框,但为什么不呢?对于使用的主题,您必须先安装它,例如:pip install ttkthemes然后是代码# importsfrom tkinter import *from tkinter import ttkfrom ttkthemes import themed_tk as tkthemefrom PIL import ImageTk, Imagefrom tkinter import messagebox# making new themed windowroot = tktheme.ThemedTk()root.title('Take selection')root.get_themes()root.set_theme('vista')# message to be shown by the boxmessage = 'Here is a custom messagebox.'# defining functionsdef click1(): root.destroy() return 'A'def click2(): root.destroy() return 'B'def click3(): root.destroy() return 'C'# creating white frameframe1 = Frame(height=139, width=440, bg='white')frame1.grid(row=0, column=0)# creating gray frameframe2 = ttk.Frame(height=50, width=440)frame2.grid(row=1, column=0)# importing the image, any image can be used(for the question mark)dir = Image.open('Blue_question.png')dir = dir.resize((50, 50), Image.ANTIALIAS)img_prof = ImageTk.PhotoImage(dir)img_label = Label(root, image=img_prof, bg='white')img_label.grid(row=0, column=0, sticky=W, padx=25)# defining main labelcust_messagebox = Label(root, text=message, font=('Arial', 10), bg='white')cust_messagebox.grid(row=0, column=0, sticky=W, padx=(95, 0))# defining buttonsbutton1 = ttk.Button(root, text='A', command=click1)button1.grid(row=1, column=0, sticky=W, padx=30, ipadx=10)button2 = ttk.Button(root, text='B', command=click2)button2.grid(row=1, column=0, ipadx=10)button3 = ttk.Button(root, text='C', command=click3)button3.grid(row=1, column=0, sticky=E, padx=(0, 30), ipadx=10)# keeping the app aliveroot.mainloop()对于更大的消息,您可能希望增加框架的宽度以及小部件的填充。如果有任何疑问或错误,请告诉我。