Python Forum
Tkinter - Issues with "iconbitmap" method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter - Issues with "iconbitmap" method
#1
hi guys,

below my code:
#!/usr/bin/python3

from tkinter import *
from tkinter import ttk

class MainWindow:
    
    def __init__(self, parent):    
        self.parent = parent
        parent.title("My Software")
        parent.iconbitmap("icon.ico")
        parent.geometry("530x515+360+200")
        parent.resizable (width=False, height=False)
        parent.configure(background="#f0f0f0")
        tools = IntVar()
        tools.set(1)
        ttk.Radiobutton(self.parent, text = "Menu 1 (my window has an icon!)", variable = tools, value = 1).pack()
        ttk.Radiobutton(self.parent, text = "Menu 2 (my window hasn't an icon!)", variable = tools, value = 2).pack()
        self.tools = tools
        ttk.Button(self.parent, text = "OK", command = self.__OpenTool).pack()
        ttk.Button(self.parent, text = "Settings", command = self.__OpenSettings).pack()
        
    def __OpenTool(self):
        tool = self.tools.get()
        if tool == 1:
            FirstWindow(self.parent)
            self.parent.withdraw()
        elif tool == 2:
            SecondWindow(self.parent)
            self.parent.withdraw()

    def __OpenSettings(self):
        SixthWindow(self.parent)


class FirstWindow:
    
    def __init__(self, parent):     
        self.parent = parent
        self.window = Toplevel(parent=None)
        self.window.title("My Software - Menu 1 (my window has an icon!)")
        self.window.iconbitmap("icon.ico")
        self.window.geometry("530x515+360+200")
        self.window.resizable (width=False, height=False)
        self.window.configure(background="#f0f0f0")
        self.window.protocol("WM_DELETE_WINDOW", self.__CloseEvent)
    
    def __CloseEvent(self):
        self.parent.deiconify()
        self.window.destroy()


class SecondWindow:
    
    def __init__(self, parent):        
        self.parent = parent
        self.window = Toplevel(parent=None)
        self.window.title("My Software - Menu 2 (my window hasn't an icon!)")
        self.window.geometry("530x515+360+200")
        self.window.resizable (width=False, height=False)
        self.window.configure(background="#f0f0f0")
        self.window.protocol("WM_DELETE_WINDOW", self.__CloseEvent)
    
    def __CloseEvent(self):
        self.parent.deiconify()
        self.window.destroy()


class SixthWindow:
    
    def __init__(self, parent):      
        self.parent = parent
        self.window = Toplevel(parent=None)
        self.window.title("My Software - Settings")
        self.window.iconbitmap("icon.ico")
        self.window.geometry("530x515+360+200")
        self.window.resizable (width=False, height=False)
        self.window.configure(background="#f0f0f0")       
        self.window.protocol("WM_DELETE_WINDOW", self.__CloseEvent)
    
    def __CloseEvent(self):
        self.parent.deiconify()
        self.window.destroy()


def main():
    root = Tk()
    app = MainWindow(root)
    root.mainloop()

if __name__ == "__main__":
    main()
if you choose to open one of the two avalable menus, a new window will appear and the main window hides itself. it's the same for the new window opened via the "Settings" button, but in this case the main window will not disappear. the setting and first menu windows have an icon, instead the second menu window uses the default icon from Tkinter.

the software works, but there is a really annoying behaviour. if you open the first menu window first of the the other ones, it will start always below another window already opened from your operating system (see my gif attached). it happens just one time only with the first menu window. I think it depends by the "self.window.iconbitmap("icon.ico")" and "self.parent.withdraw()" statements, because this issue doesn't happen with the second menu and "Settings" windows

how can I fix this issue?

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
Tkinter - Issues with "iconbitmap" method - by aquerci - May-20-2020, 11:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TKinter Widget Attribute and Method Quick Reference zunebuggy 3 786 Oct-15-2023, 05:49 PM
Last Post: zunebuggy
  [Tkinter] scheduling and timining issues using mqtt and tkinter kiko4590 2 1,781 Apr-11-2022, 08:23 AM
Last Post: kiko4590
  tkinter -- after() method and return from function -- (python 3) Nick_tkinter 12 7,228 Feb-20-2021, 10:26 PM
Last Post: Nick_tkinter
  Tkinter menu font size -method to change tonycat 2 7,700 Oct-11-2020, 02:43 AM
Last Post: tonycat
  tkinter get method is not accepting value when called by function jagasrik 1 2,494 Sep-16-2020, 05:28 AM
Last Post: Yoriz
  tkinter get method is not accepting value jagasrik 4 2,247 Sep-15-2020, 05:41 PM
Last Post: jagasrik
  Tkinter Listbox tab char issues ashtona 4 4,389 Mar-27-2018, 12:28 PM
Last Post: ashtona
  Widget placement issues with tkinter grid thread 1 mgtheboss 2 4,317 Jan-09-2018, 03:59 PM
Last Post: SmokerX
  Help with tkinter Button and Label interaction issues ... sealyons 0 4,678 Jun-01-2017, 06:58 PM
Last Post: sealyons

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020