0

My problem is that i have an Main-Class with an button-click function, where if i click the button, the EntryBox will be opened and in the button-click function i want to create the folder too, but i dont know how to "stop" the mainWindow while the EntryBox-Window is open to get the value(Folder name).

@BryanOakley Minimal, Complete, and Verifiable example:

That's my msBox.py

import tkinter as tk

FolderName = ""

class EntryBox:
def __init__(self, Text):
    self.root = tk.Tk()
    self.textBox = tk.Entry(self.root)
    self.EBOKAY = tk.Button(self.root, text="Okay")
    self.EBOKAY.bind("<Button-1>", self.EBOKAY_click)
    self.EBLabel = tk.Label(self.root, text=Text)

    self.EBLabel.pack()
    self.textBox.pack()
    self.EBOKAY.pack()

    self.root.mainloop()

def EBOKAY_click(self, event):
    global FolderName
    FolderName = self.textBox.get()
    self.root.destroy()

Here is my next file gui.py:

import tkinter as tk
import os
import msBox

# variables
path = "/"

class GUI:
    def __init__(self, master):
        self.button1 = tk.Button(master, text="Set")
        self.button1.bind('<Button-1>', self.button1_click)
        self.button1.pack()

    def button1_click(self, event):
        test = msBox.EntryBox("New folder name:")
# Here is need a wait-Statement or anything else
        os.mkdir(path + msBox.FolderName)

Here is my main.py:

import tkinter as tk
import gui

def main():
    root = tk.Tk()
    design = gui.GUI(root)
    root.mainloop()

if __name__ == '__main__': 
    main()
Banner24
  • 1
  • 2
  • Are you creating more than once instance of `Tk`? If so, that's definitely part of the problem. Please create a [mcve]. – Bryan Oakley Jun 30 '18 at 16:42
  • 1
    @BryanOakley : what 'problem' as far as I can tell, the OP just wants some code to make the main windy unresponsive until the second one closes. (Correct of if I'm wrong, OP) – Artemis Jun 30 '18 at 20:40
  • @BryanOakley yes im using 2 instance of Tk. – Banner24 Jul 01 '18 at 10:12
  • In general it is bad practice to have 2 `Tk` windows. Instead, replace the second with a `Toplevel` instance. You can use them just like `Tk` instances. – Artemis Jul 01 '18 at 21:06

0 Answers0