2

I'm making a main code in Python 3.6 called gui_check.py.

The code looks like this:

from tkinter import *
from urlread import givenumbers

top = Tk()
top.geometry("400x400")

B = Button(top, text = "Hello", command = givenumbers())
B.place(x = 50,y = 50)

top.mainloop()

In this code, there is a function called givenumbers() which is a function from another file (called urlread.py) that prints numbers.

The result I wanted to get is a gui with a button that when I click on it, it calls the function givenumber(). However, the result I get is that when I run the code it runs givenumber() (print the numbers) while opening the gui even without me clicking on the button.

1

1 Answer 1

2

Remove the parentheses in:

B = Button(top, text = "Hello", command = givenumbers())

So you should have:

B = Button(top, text = "Hello", command = givenumbers)

instead.

Read http://effbot.org/zone/tkinter-callbacks.htm

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.