3/17/2023 0 Comments Python popup windowNote the hack needed for resizing the dark background of our window: The function update_width updates the width of the title area, of the content area and of the popup window. This is the "dlgback_green.png" image we use as background in our window: pbutton = Button ( text = 'Close', size_hint_y = None, height = "25dp", background_normal = "atlas://data/images/defaulttheme/vkeyboard_background" ) self. content = Label ( size_hint_y = None, text = txt, halign = 'justify', font_size = "16sp", markup = True, text_size = ( self. pscroll = ScrollView ( do_scroll_x = False ) self. separator = BoxLayout ( size_hint_y = None, height = "1dp" ) self. width - dp ( 20 ), None ), text = title, halign = 'left', font_size = "16sp", color = ( 0, 1, 1, 1 ), markup = True ) self. title = Label ( size_hint_y = None, text_size = ( self. playout = BoxLayout ( orientation = 'vertical', padding =, spacing = "5dp" ) self. background_color = ( 0, 0, 0, alpha ) self. Note the bindings we make with the functions that update the size of our window parts. A button (a Button object for closing the window).Inside the scrolling view, we put the text content of our window (a Label object). A separator line (a second BoxLayout object in which we draw a thin Rectangle).As long as you always pass in the master argument when creating those variables, you shouldn't encounter any problems.In the _init_ function, we define a BoxLayout object to put inside the various parts that constitute our popup window: It uses multiple instances of Tk() so you need to be careful when creating StringVar/ IntVar/./ PhotoImages. That is done using: pop_window.mainloop(1) It uses multiple instances of Tk() and waits until there is only 1 window left open before continuing with the for loop. Try something like this: import tkinter as tkfrom tkinter import ttk import time# Force you to pass in the master argument when creating widgets:tk._support_default_root = Falsedef popup(): global pop_window pop_window = tk.Tk() pop_window.geometry("200x100") entry = tk.Entry(pop_window) entry.pack() button = tk.Button(pop_window, text="Enter", command=pop_stroy) button.pack() # Wait until there is only 1 window left open pop_window.mainloop(1)def button_(): global done if done: done = False for i in range(3): popup() done = Truedone = Trueroot = tk.Tk()root.geometry("200x200")button = tk.Button(root, text="Click me", command=button_)button.pack()# Close the program when the main window is destroyed:# Instead here you can call a function that sets `done` to `True`,# Closes the main window as well as the `pop_window` if it existsroot.protocol("WM_DELETE_WINDOW", exit)# Wait until all windows have been closedroot.mainloop()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |