Python Forum
[Tkinter] Spawn sub-window with button press
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Spawn sub-window with button press
#1
Hey, I'm trying to open a sub-window on top of my main window for a specific time, then close it. I'm going the tkinter.Toplevel route for this and plan on destroying it with subwindow.destroy(). But I keep getting an error that I have no idea what to do with. Code:
class MainWindow(ttk.Frame):
    def __init__(self, parent):
        ttk.Frame.__init__(self)
        ttk.Frame.grid(self, column=0, row=0, sticky=('N', 'E', 'S', 'W'))
        ttk.Frame.columnconfigure(self, 0, weight=1)
        ttk.Frame.rowconfigure(self, 0, weight=1)
        self.mem_exists = tkinter.StringVar()
        self.reg_scan = tkinter.StringVar()
        self.widgets()

    def widgets(self):
        self.mem_labl1 = ttk.Label(self, text='Memory Dumps:')
        self.mem_labl1.grid(column=0, row=0)
        self.mem_labl2 = ttk.Label(self, textvariable=self.mem_exists)
        self.mem_labl2.grid(column=0, row=1)
        self.mem_buton = ttk.Button(self, text='Delete', command=self.delete_dmps)
        self.mem_buton.grid(column=0, row=2)
        self.dmp_separ = ttk.Separator(self, orient='horizontal')
        self.dmp_separ.grid(column=0, row=3, rowspan=1, sticky=('EW'))
        self.scn_labl1 = ttk.Label(self, text='Scan for Dumps')
        self.scn_labl1.grid(column=0, row=4)
        self.scn_buton = ttk.Button(self, text='Scan', command=self.scan_pressed)
        self.scn_buton.grid(column=0, row=5)
        self.vrt_separ = ttk.Separator(self, orient='vertical')
        self.vrt_separ.grid(column=1, row=0, rowspan=6, sticky=('NS'))
        self.reg_labl1 = ttk.Label(self, text='Unneeded Keys')
        self.reg_labl1.grid(column=2, row=0)
        self.reg_labl2 = ttk.Label(self, textvariable=self.reg_scan)
        self.reg_labl2.grid(column=2, row=1)
        self.reg_buton = ttk.Button(self, text='Delete', command=self.delete_keys)
        self.reg_buton.grid(column=2, row=2)
        ......
    def scan_pressed(self):
        self.sub_win = tkinter.Toplevel(self, root) <----- ERROR HERE
        self.write_dumps()
        size = self.get_size()
        self.mem_exists.set(f'{size} KB of memory dumps found!')
When I press the button (scn_buton) I want it to spawn a little window with a label that says "scanning..." (or something of that nature), but it gives me this error:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "c:\users\mark\downloads\practice_gui_2.py", line 83, in scan_pressed
self.sub_win = tkinter.Toplevel(self, root)
File "C:\Python37\lib\tkinter\__init__.py", line 2334, in __init__
if wmkey in cnf:
File "C:\Python37\lib\tkinter\__init__.py", line 1489, in cget
return self.tk.call(self._w, 'cget', '-' + key)
TypeError: can only concatenate str (not "int") to str

I have no clue where to even begin on that one. Google results turn up things not related to tkinter.

malonn

Well, I figured out why the window wouldn't spawn. The fix was to remove the master from the call to Toplevel() like so
self.sub_win = tkinter.Toplevel(self)
but the window doesn't spawn until after the rest of the code for that method ("scan_pressed") is run. Why is that? The code calls os.walk which takes a while to complete and I want the second window to block it while it happens.
Reply


Messages In This Thread
Spawn sub-window with button press - by malonn - Oct-27-2018, 11:04 PM
RE: Spawn sub-window with button press - by woooee - Oct-27-2018, 11:40 PM
RE: Spawn sub-window with button press - by malonn - Oct-28-2018, 12:25 AM
RE: Spawn sub-window with button press - by malonn - Oct-28-2018, 02:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 662 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 5,240 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,286 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  .get() invoke after a button nested press iddon5 5 3,333 Mar-29-2021, 03:55 AM
Last Post: deanhystad
Question closing a "nested" window with a button in PySimpleGUI and repeating this process Robby_PY 9 13,724 Jan-18-2021, 10:21 PM
Last Post: Serafim
  tkinter touchscreen scrolling - button press makes unwanted scrolling nanok66 1 4,072 Dec-28-2020, 10:00 PM
Last Post: nanok66
  Closing window on button click not working kenwatts275 4 3,855 May-03-2020, 01:59 PM
Last Post: deanhystad
  Anytime I press the button, the result is depicted Jionni 2 2,259 Feb-24-2020, 10:08 AM
Last Post: Jionni
  tkinter window and turtle window error 1885 3 6,808 Nov-02-2019, 12:18 PM
Last Post: 1885
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,076 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

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