0

To be honest i am very new to python and i have written some scripts with the help from everyone but i stumbled onto something that i can't find anywhere. I'm trying to create a pysimplegui script that will present a input text for the user to type a name and a submit or cancel button. Cancel button will terminate the script right away but if the user presses submit then it will take the value from the input text, and create a directory on a location with that name

For example: The user typed "test", then pressed submit and finally it will create the "test" directory in the c:\

This is the simple GUI i have:

layout = [[sg.Text('Please enter the name of the directory:')],[sg.InputText()],
[sg.Submit(), sg.Cancel()]]

window = sg.Window('directory creator', layout)

PS, been lurking around the website but decided to sign up and ask the question

wallisers
  • 388
  • 3
  • 16
Ben Palma
  • 11
  • 1

1 Answers1

0

You're missing the 3rd and final part of the program, actually reading the window you've created.

You need these 2 statements if you're not going to keep the window open after the button click:

event, values = window.read()
window.close()

If you wanted to then check to see what button was clicked and then act upon the button click, add something like this:

if event == 'Submit':
    os.mkdirs(values[0])
Mike from PSG
  • 5,312
  • 21
  • 39
  • Sorry my bad i should have place that part of the code in the question... I do have that. Now i did manage to get a working model using tkinter and creating a def, but how would i apply the same scenario on here? I figured if i can make pysimplegui to read a def then i should be good :) – Ben Palma Oct 14 '19 at 06:27
  • What's a "def"? Can you edit your question to include the missing information you commented that you do have? What I'm finding confusing is that there is no actual question asked in your main post and the question in the comment I'm unable to understand. I think what you're missing is an if statement checking to see if the variable event == 'Submit'. If that's true, then the entered text will be accessible using values[0]. – Mike from PSG Oct 20 '19 at 15:04