SimpleGui inputs into a variable

2k Views Asked by At

On simplegui I want there to be an input box called login_gui that puts the data from the input into the variable login_variable, not into a defined function.

import simplegui
frame = simplegui.create_frame("screen", 500, 500)
login_gui = frame.add_input("Login?", login_variable, 20)
 ..something with login_variable

Is there any way to do this, or is it only with defined functions that this works?

3

There are 3 best solutions below

4
On

I don't know. But using tkinter or pyside is very simple and then you have all options avaliable.

updated with an example

Basically pyside is better, but tkinter works out of the box. If you just want a simple gui, just use tkinter

from Tkinter import *

def go():
    print E1.get()
top = Tk()
L1 = Label(top, text="User Name")
L1.pack()
E1 = Entry(top, bd =5)
E1.pack()

But = Button(top, text="go", command=go)
But.pack()
top.mainloop()
0
On

You can retrieve the input string by calling the get_text() method of the variable that is assigned to the input field.

login_variable = login_gui.get_text()

Please note that you will still have to define an input handler function somewhere, but can leave it blank (and do not name it login_variable as you're using it to store the input text)

def input_handler(input):
     pass

login_gui = frame.add_input("Login?", input_handler, 20)

Source: SimpleGui documentation.

0
On

you can just call the box with name and use it

name = enterbox("Enter the company name:", "Name") msgbox("Hello " + name) # will show what you entered