Python Forum
How to edit Tkinter Minimize, Maximize, and Close Buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to edit Tkinter Minimize, Maximize, and Close Buttons
#1
sorry for my bad English,

1. in tkinter I tried to hide Minimize,
maximize button, but I only found :
Top.resizable(0,0)
what command to disable them?

2. I tried to edit the close button with
Top.withdraw()
what command to do that?

3. how to check if a Toplevel() window exists?
window = Toplevel(None)
thank you for reading,
have a nice day
Reply
#2
Please show code in context, as we cannot see how Top was defined.
Is 'Top' an instance of Tk() ?
Reply
#3
ah sorry
from tkinter import * root = Tk() root.title("Main Window") root.geometry("200x200") def show(): Top.deiconify() def hide(): Top.withdraw() Top = Toplevel() Top.title("Child Window") Top.geometry("400x400") Top.withdraw() Button(root, text="Show", command=show).pack(pady=10) Button(root, text="Hide", command=hide).pack(pady=10) root.mainloop()
Reply
#4
This will remove the titlebar

import tkinter as tk root = tk.Tk() root.overrideredirect(True) # This removes the title bar. root.mainloop()
More can be found here
https://blog.finxter.com/5-best-ways-to-...title-bar/
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply
#5
(Apr-26-2024, 10:11 AM)menator01 Wrote: This will remove the titlebar

import tkinter as tk root = tk.Tk() root.overrideredirect(True) # This removes the title bar. root.mainloop()
More can be found here
https://blog.finxter.com/5-best-ways-to-...title-bar/
thank you for the reply and answer
i just know that thing called "title bar"
but i just want to hide or disable the minimize and maximize buttons, but keep the close button
anyway I just give you a reputation point
Reply
#6
From the link I provided, I don't think you can directly edit the titlebar as it's managed by the systems window manager.

Probably best option is to use root.resizable(False, False)

A way to detect an open window. Not elegant but works

import tkinter as tk root = tk.Tk() root.minsize(400,200) def window(): top = tk.Toplevel(None) top.geometry('+300+300') if top.winfo_exists(): label.config(text='Window is open') top.protocol('WM_DELETE_WINDOW', lambda: change(top)) def change(top): label.config(text='Window is closed') top.destroy() label = tk.Label(root, text='Window is closed') label.pack() btn = tk.Button(root, text='Open Window', command=window) btn.pack(pady=10) root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply
#7
(Apr-26-2024, 10:44 AM)menator01 Wrote: From the link I provided, I don't think you can directly edit the titlebar as it's managed by the systems window manager.

Probably best option is to use root.resizable(False, False)

A way to detect an open window. Not elegant but works

import tkinter as tk root = tk.Tk() root.minsize(400,200) def window(): top = tk.Toplevel(None) top.geometry('+300+300') if top.winfo_exists(): label.config(text='Window is open') top.protocol('WM_DELETE_WINDOW', lambda: change(top)) def change(top): label.config(text='Window is closed') top.destroy() label = tk.Label(root, text='Window is closed') label.pack() btn = tk.Button(root, text='Open Window', command=window) btn.pack(pady=10) root.mainloop()

i tried to answer question number 3:
 if top.winfo_exists(): top.destroy()
Error:
NameError: name 'top' is not defined
anyway, thank you for reply
Reply
#8
Ok i found out all
1.
Top.attributes('-toolwindow', True)
2.
def wd(): Top.withdraw() Top.protocol("WM_DELETE_WINDOW", wd)
3.
try: top.winfo_exists() except: print("Top Do not exist")
menator01 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Minimize function with SciPy PierreLCV 3 4,695 Apr-05-2024, 07:51 AM
Last Post: paul18fr
  How to Minimize ADB window OomKoos 0 1,284 Dec-29-2023, 12:41 PM
Last Post: OomKoos
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 2,786 Jan-08-2022, 12:13 PM
Last Post: law
  Build a matrix by pressing buttons of an interface in Tkinter which extract data from juandiegopulla 1 3,502 Sep-13-2021, 07:28 PM
Last Post: deanhystad
  Can I minimize the code??? shantanu97 4 3,864 Mar-23-2021, 05:26 PM
Last Post: jefsummers
  Buttons or Radio Buttons on Tkinter Treeview draems 0 4,533 Oct-31-2017, 04:06 AM
Last Post: draems

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.