Python - tkinter.messagebox cannot see title and showerror icon in macOS

382 views Asked by At

I use tkinter to do GUI. When use messagebox, that can not see title and showerror icon is a file, just like that:

enter image description here

This is my env:

  1. macOS / windows 10
  2. python 3.8.13
  3. tk 8.6

And this is my code

import tkinter
from tkinter import messagebox

window = tkinter.Tk()
window.withdraw()
messagebox.showerror(title="error title", message="for test message")
window.destroy()

I want to see title and error icon, just like windows system. How can I do to fix this progrem, thanks.

2

There are 2 answers

0
toyota Supra On
window = tkinter.Tk()
root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file=your path))
messagebox.showerror(title="error title", message="for test message")
root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file=your path))
0
D.L On

If there are features that are different for different operating systems, then you can determine the operating system like this:

import sys

p = sys.platform

if p == "linux" or p == "linux2":
    # linux
    print('using linux')
elif p == "darwin":
    # OS X
    print('using mac')
elif p == "win32":
    # Windows...
    print('using windows')

Alternatively the mac settings (so not tkinter). How are the error messages currently displayed on the pc as one would expect tkinter to be consistent with this.