Back to Blog
Tkinter set icon6/11/2023 This is a basic example of creating a window in which the icon has been set using iconbitmap. For using this method, the bitmap image should be an icon type with. Iconbitmap is used to set an icon of a window or a frame to bitmap. Label2 = Label(code, text=text1, font="Times") Label1 = Label(code, text=text, font=thefont) Text = "This example if for creating an icon " Program.iconphoto(False, tk.PhotoImage(file='C:/Users/afu/Desktop/tk/Folder.png'))Ĭ("program.iconphoto method example") This example represents a way to create a window that sets up an image as its icon using icon photo and along with it, it also represents a way to set up different fonts in a window. Advance Iconphoto() usage example with texts using multiple fonts Label4 = Label(framedesign, background='DarkSeaGreen4', width = 15)Ĭ("Advance iconphoto() method'") Label3 = Label(framedesign, background='DarkSeaGreen3',width = 15)īutton4 = Button(framedesign, text='Me too', background='pink',activebackground = 'DarkSeaGreen4') Label2 = Label(framedesign, background='SlateGray4',width = 15)īutton3 = Button(framedesign, text='I am Green', background='crimson', activebackground = 'DarkSeaGreen3' ) Label1 = Label(framedesign, background='SlateGra圓', width = 15)īutton2 = Button(framedesign, text='Mine too',background='blue', activebackground = 'SlateGra圓') The method for setting up an icon is iconphoto and it has been used the same way like it is done in the previous example.įramedesign = Frame(code, borderwidth=10)īutton1 = Button(framedesign, activebackground = 'SlateGra圓', text='Change my color', bg = 'red') Along with the buttons, there are colored labels also. Here the window contains buttons which has a background color and also an active background color. This example is a more advanced version of the window created in the last example. P1 = PhotoImage(file = 'C:/Users/afu/Desktop/tk/Git.png') # And Image should be in the same folder where there is script saved Here the image has been made the object of PhotoImage class and it is used with iconphoto to set the image as the icon. When we close the window it will still appear in the Taskbar as a System Tray icon.This is a basic example of creating a top-level window and putting up an image as its icon. If you will run the above code, it will display a window. Win.protocol('WM_DELETE_WINDOW', hide_window) Icon=pystray.Icon("name", image, "My System Tray Icon", menu) Menu=(item('Quit', quit_window), item('Show', show_window)) # Hide the window and show on the system taskbar # Define a function to show the window again # Create an instance of tkinter frame or window Import the required libraries − Pystray, Python PIL or Pillow.ĭefine a function hide_window() to withdraw the window and provide the icon in the system tray.Īdd and define two menu items, " Show" and " Quit".Īdd a command in the menu items by defining a function for Show and Quit. To create a System Tray icon, you can follow these steps, To install pystray in your machine you can type " pip install pystray" command in your shell or command prompt. It has many inbuilt functions and methods that can be used to configure the system tray icon of the application. To create a System Tray icon of a tkinter application, we can use pystray module in Python. The system tray icon is visible in the taskbar. It typically shows which application is currently running. A System Tray icon is used for showing the application’s running state in the taskbar.
0 Comments
Read More
Leave a Reply. |