Reputation: 13
Coordinate_1_X = input (" Enter Coordinate point 01 _ X: ")
Coordinate_1_Y = input (" Enter Coordinate point 01 _ Y: ")
Coordinate_2_X = input (" Enter Coordinate point 02 _ X: ")
Coordinate_2_Y = input (" Enter Coordinate point 02 _ Y: ")
Coordinate_3_X = input (" Enter Coordinate point 03 _ X: ")
Coordinate_3_Y = input (" Enter Coordinate point 03 _ Y: ")
Coordinate_4_X = input (" Enter Coordinate point 04 _ X: ")
Coordinate_4_Y = input (" Enter Coordinate point 04 _ Y: ")
The above data are mandatory to start my webdriver selenium app, once I add input_4 the code starts.
My first question is (If I want to use Tkinter to allow the end user to add this info in GUI, I have to make the Tkinter code in another Python file or not ?)
If the answer to this question is (No, you can add Tkinter code in the same main app code) so I have the second question as follows ... (How can I let the code run once submit button in Tkinter code clicked ?)
Upvotes: 0
Views: 123
Reputation: 15224
Here is a simple example to show you haw to get input from a user on a GUI and then do something with it using a function/method.
import tkinter as tk
class Example(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
tk.Label(self, text=" Enter Coordinate point 01 _ X: ").grid(row=0, column=0)
self.entry1 = tk.Entry() # this is the widget the user can type in
self.entry1.grid(row=0, column=1)
tk.Label(self, text=" Enter Coordinate point 01 _ Y: ").grid(row=1, column=0)
self.entry2 = tk.Entry()
self.entry2.grid(row=1, column=1)
# This button will run the function that creates a new window with the user input
tk.Button(self, text="Do something", command=self.do_something).grid(row=2, column=0, pady=5)
def do_something(self):
top = tk.Toplevel(self)
x = self.entry1.get() # the get() method will grab a string of the content of the entry widget
y = self.entry2.get()
tk.Label(top, text="You provided coords for point 01 X: {} and Y: {}!".format(x, y)).grid(row=0, column=0)
if __name__ == "__main__":
Example().mainloop()
Results:
After pressing the button:
Upvotes: 1