0

I made an app that opens urls in a web browser, when you enter them into a gui.

from tkinter import *
import webbrowser

def WebOpen():
    url = (WebEntry.get())
    webbrowser.open(url)

gui = Tk()

gui.after(1, lambda: gui.focus_force)

gui.geometry("1920x1040")

gui.resizable(False, False)

gui.attributes('-fullscreen',True)

gui.configure(bg="black")

ExitWindow = Label(gui, text="To Quit This Computer Application, On Your Keyboard, Press and Hold the ALT and the F4 keys at the bottom and top of your keyboard respectively.", fg="white", bg="black", font="arial, 21")
ExitWindow.place(x=30,y=5)

WebEntry = Entry(gui, font="arial, 21")
WebEntry.place(x=100,y=400)

WebButton = Button(gui, text="Take Me There!",font="arial, 21",command=WebOpen())
WebButton.place(x=200, y=500)

gui.mainloop()

I tried to use webbrowser and tkinter to make an app that opens a webpage, but as soon as my program started, it opened file explorer (I think because of an empty path or something.)

1
  • 3
    I believe the reason is because you used command=WebOpen(). The purpose of the command argument is to give the name of a function to be called later. But because you included the parentheses () after the function, it is called immediately when the button is created. I think you should use command=WebOpen instead, without the parentheses. Commented Feb 23, 2024 at 13:07

1 Answer 1

1

Remove the parenthesis in the line 26. It works alright after removal

WebButton = Button(gui, text="Take Me There!",font="arial, 21",command=WebOpen)
Sign up to request clarification or add additional context in comments.

2 Comments

When writing an answer, please try to explain the solution or close the question as a duplicate. That way OP is less likely to make the same mistake again.
If anyone had the same issue, and want to know why, please check John Gordon's comment on the original answer! Thank you both!

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.