1

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.

0

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.