Change title of Tkinter application in OS X Menu Bar

前端 未结 2 557
日久生厌
日久生厌 2020-12-30 07:18

When you create an application with a GUI using Tkinter in Python, the name of your application appears as \"Python\" in the menu bar on OS X. How can you get it to appear a

2条回答
  •  孤独总比滥情好
    2020-12-30 07:47

    May not be quite what you need but I am surprised no one has mentioned the simple, platform independent way (works with Python 3.x on Win 7) :

    from tkinter import Tk
    
    root = Tk()
    root.title( "Your title here" )  # or root.wm_title
    

    and if you want to change the icon:

    ''' Replace the default "Tk" icon with an Application-specific icon '''
    ''' (that is located in the same folder as the python source code). '''
    
    import sys
    from tkinter import PhotoImage 
    
    program_directory = sys.path[ 0 ]
    
    IconFile = os.path.join( program_directory ) + "\ApplicationIcon.gif" 
    IconImage = PhotoImage( file = IconFile ) 
    
    root.tk.call( 'wm', 'iconphoto', root._w, IconImage )
    
    root.mainloop()
    

提交回复
热议问题