-1

I have been trying everything and im pretty much exhausted. The problem is that there comes up an error "Can't convert 'Entry' object to str implicitly" And i doesnt find any way to make it work.

Here is the code:

from tkinter import *

def wcommand():
     import webbrowser
     new=2;
     url='https://'+w
     webbrowser.open(url,new=new);

root = Tk()


Label (root, text="Nettadresse:").grid(row=0)
w = Entry(root)
w.grid(row=0, column=1,)

b1 = Button(root, text='Kjør!', command=wcommand).grid()

root.mainloop()
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

1

Use .get method to get the text from the Entry widget:

url='https://{}'.format(w.get())
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
0

There are several things wrong with your code. First, you don't need those semicolons. Second, you don't want url='https://'+w there, you want url='https://'+w.get() there. The .get() will retrieve the string contents of that Entry widget. Third, instead of:

Label (root, text="Nettadresse:").grid(row=0)

you should do:

mylabel = Label(root, text="Nettadresse:")
mylabel.grid(row=0)

This will ensure that you can refer to this Label object later, in case you want to reconfigure it or move it or something. Fourth, you should import webbrowser as the second line of your code, right below from tkinter import *, rather than every time that function is called.

TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97