Suppose there two functions name Func1 and func2 and there one button name OK, How can I execute func1 or func2 if user Entry is 1 and press “OK” then func1 will executed, and if Entry is two then fun2 will executed.
1 Answer
Check this example out, where ive used messagebox to show some action, you can replace it with whatever you have to do inside the function.
from tkinter import *
from tkinter import messagebox
root = Tk()
def func1():
messagebox.showinfo('Pressed','you pressed 1')
def func2():
messagebox.showinfo('Pressed','you pressed 2')
def hello():
if int(e.get()) == 1:
func1()
elif int(e.get()) == 2:
func2()
else:
messagebox.showinfo('Invalid','Enter valid text')
l = Label(root, text='Random Text')
l.pack()
e = Entry(root)
e.pack(padx=10, pady=20)
b = Button(root, text='Click me',command=hello)
b.pack(pady=10)
root.mainloop()
Hope it was of some help and you get an idea.
Cheers