How to stop the mainWindow while opened a new Window and get my Value


How to stop the mainWindow while opened a new Window and get my Value



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()





Are you creating more than once instance of Tk? If so, that's definitely part of the problem. Please create a Minimal, Complete, and Verifiable example.
– Bryan Oakley
Jun 30 at 16:42



Tk





@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 Fowl
Jun 30 at 20:40





@BryanOakley yes im using 2 instance of Tk.
– Banner24
Jul 1 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 Fowl
Jul 1 at 21:06


Tk


Toplevel


Tk









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask

NSwag: Generate C# Client from multiple Versions of an API