Reputation: 1053
I am currently trying to turn a Python script I use regularly into an application by using Platypus. However, my script prompts the user for input several times and uses that input to construct a URL that is being used to make API requests. Here is an example of how this is used in my script:
member_id = raw_input("What member id will you be using? ")
The data taken from the user (and stored as a variable) is then used like this:
url_member = "https://api.example.com/member?member_id="+str(member_id)
Since the application created using Platypus won't allow for user input (based on the way I am requesting it through my script) I was going to try and use Tkinter as well. However, I have read through the documentation and am confused when it comes to the syntax (I am still new to Python in general).
Can anyone help, or show an example of how I can change my request for user input (based on my example above) using Tkinter so the application will work?
I am also using Python 2.7.
Upvotes: 0
Views: 6341
Reputation: 15236
You can use the Entry()
widget to get the user input as a variable.
A user can type in there ID and then hit the submit button. This button can be tied to a function that will do anything you need it to form there.
import tkinter as tk # Python 3 import
# import Tkinter as tk # Python 2 import
root = tk.Tk()
def my_function():
current_id = my_entry.get()
url_member = "https://api.example.com/member?member_id="+str(current_id)
print(url_member)
#do stuff with url_member
my_label = tk.Label(root, text = "Member ID# ")
my_label.grid(row = 0, column = 0)
my_entry = tk.Entry(root)
my_entry.grid(row = 0, column = 1)
my_button = tk.Button(root, text = "Submit", command = my_function)
my_button.grid(row = 1, column = 1)
root.mainloop()
Upvotes: 2