Removing minimize/maximize buttons in Tkinter

前端 未结 3 1812
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 08:44

I have a python program which opens a new windows to display some \'about\' information. This window has its own close button, and I have made it non-resizeable. However, th

相关标签:
3条回答
  • 2020-11-30 09:11
    from tkinter import  *
    
    qw=Tk()
    qw.resizable(0,0)      #will disable max/min tab of window
    qw.mainloop()
    

    from tkinter import  *
    
    qw=Tk()
    qw.overrideredirect(1) # will remove the top badge of window
    qw.mainloop()
    

    here are the two ways to disable maximize and minimize option in tkinter

    remember the code for button shown in image is not in example as this is solution regarding how to make max/min tab nonfunctional or how to remove

    0 讨论(0)
  • 2020-11-30 09:15

    Windows

    For windows, you can use -toolwindow attribute like that:

    root.attributes('-toolwindow', True)
    

    So if you want complete code, it's that

    from tkinter import *
    
    from tkinter import ttk
    
    root = Tk()
    
    root.attributes('-toolwindow', True)
    
    root.mainloop()
    

    Other window.attributes attributes:

    -alpha
    -transparentcolor
    -disabled
    -fullscreen
    -toolwindow
    -topmost
    

    Important note this is only working with Windows. Not MacOS

    Mac

    With mac you can use overredirect attribute and a "x" button to close the window and this will do the job. :D like that:

    from tkinter import *
    
    from tkinter import ttk
    
    window = Tk()
    
    window.overredirect(True)
    
    Button(window, text="x", command=window.destroy).pack()
    
    window.mainloop()
    

    Inspired by https://www.delftstack.com/howto/python-tkinter/how-to-create-full-screen-window-in-tkinter/

    For me, it's working, i have a windows 7.

    Comment me if i have a error.

    0 讨论(0)
  • 2020-11-30 09:33

    In general, what decorations the WM (window manager) decides to display can not be easily dictated by a toolkit like Tkinter. So let me summarize what I know plus what I found:

    import Tkinter as tk
    
    root= tk.Tk()
    
    root.title("wm min/max")
    
    # this removes the maximize button
    root.resizable(0,0)
    
    # # if on MS Windows, this might do the trick,
    # # but I wouldn't know:
    # root.attributes(toolwindow=1)
    
    # # for no window manager decorations at all:
    # root.overrideredirect(1)
    # # useful for something like a splash screen
    
    root.mainloop()
    

    There is also the possibility that, for a Toplevel window other than the root one, you can do:

    toplevel.transient(1)
    

    and this will remove the min/max buttons, but it also depends on the window manager. From what I read, the MS Windows WM does remove them.

    0 讨论(0)
提交回复
热议问题