Python - Tkinter'da Çoklu Pencere Kullanımı Hakkında

Elinize sağlık, aradığımı buldum sanırım:

from tkinter import *
from tkinter import messagebox

def disable_windows(window):
    for child in window.winfo_children(): # Get all the child widgets of the window
        if isinstance(child, Tk) or isinstance(child, Toplevel): # Check if the child is a Tk or Toplevel window so that we can disable them
            child.attributes('-disabled', True)
            disable_windows(child)

def enable_windows(window):
    for child in window.winfo_children(): # Get all the child widgets of the window
        if isinstance(child , Tk) or isinstance(child , Toplevel): # Check if the child is a Tk or Toplevel window so that we can enable them
            child.attributes('-disabled' , False)
            enable_windows(child)

def increase_popup_count():
    global popup_count
    popup_count += 1
    if popup_count > 0: # Check if a popup is currently active so that we can disable the windows
        disable_windows(root)
    else: # Enable the windows if there is no active popup
        enable_windows(root)

def decrease_popup_count():
    global popup_count
    popup_count -= 1
    if popup_count > 0: # Check if a popup is currently active so that we can disable the windows
        disable_windows(root)
    else: # Enable the windows if there is no active popup
        enable_windows(root)

def showinfo(title, message): # A custom showinfo funtion
    increase_popup_count() # Increase the 'popup_count' when the messagebox shows up
    messagebox.showinfo(title , message)
    decrease_popup_count() # Decrease the 'popup_count' after the messagebox is destroyed

def show():
    showinfo("Test Popup", "Hello world")

root = Tk()
root.title("Main Window")
root.geometry("500x500")

popup_count = 0

toplevel = Toplevel(root)
toplevel.title("Toplevel Window")
toplevel.geometry("400x400")

toplevel_2 = Toplevel(toplevel)
toplevel_2.title("Toplevel Window of Another Toplevel")
toplevel_2.geometry("300x300")

show_button = Button(root , text = "Show popup" , command = show)
show_button.place(x = 200 , y = 200)

mainloop()

python - Disable window controls when a messagebox is created in tkinter - Stack Overflow

child.attributes('-disabled', True)

Pencereleri child oluşturu, doğrudan disable geçilebiliyor.

Bunu geliştirmeye çalışabiliriz. toplevel a alternatif doğrudan istediğimiz sayıda child pencere disble olabiliyor. Sıraylada açılabilir gibi.

EDIT:

Pencere nitelikleri nasıl değiştirilir diye düşünürken. Tkinter kütüphanesi içerisinde gördüm.

 def wm_attributes(self, *args):
        """This subcommand returns or sets platform specific attributes
        The first form returns a list of the platform specific flags and
        their values. The second form returns the value for the specific
        option. The third form sets one or more of the values. The values
        are as follows:
        On Windows, -disabled gets or sets whether the window is in a
        disabled state. -toolwindow gets or sets the style of the window
        to toolwindow (as defined in the MSDN). -topmost gets or sets
        whether this is a topmost window (displays above all other
        windows).
        On Macintosh, XXXXX
        On Unix, there are currently no special attribute values.
        """
        args = ('wm', 'attributes', self._w) + args
        return self.tk.call(args)

    attributes = wm_attributes

cpython/init.py at 3.10 · python/cpython · GitHub

EDIT2:

Günahını almışım tkinter’in:

This subcommand returns or sets platform specific attributes
        The first form returns a list of the platform specific flags and
        their values. The second form returns the value for the specific
        option. The third form sets one or more of the values. The values
        are as follows:
        On Windows, -disabled gets or sets whether the window is in a
        disabled state. -toolwindow gets or sets the style of the window
        to toolwindow (as defined in the MSDN). -topmost gets or sets
        whether this is a topmost window (displays above all other
        windows).
        On Macintosh, XXXXX
        On Unix, there are currently no special attribute values.

Sırf windows özelliklerini kullanmak için fonksiyon kullanmış. Yalnız notta yazdığı üzere bunu kullanırsanız linux uyumlu olmaz.

1 Beğeni