如何从输入框中获取自定义输入以形成特定的超链接?

How do I get custom inputs from entry boxes to form a specific hyperlink?

这是我第一次编写任何代码,因为我很快就要完成这个项目,所以我无法在 Python 中找到合适的教程。

事情是这样的:我需要编写一个带有两个输入框和一个按钮的小型 window。

该按钮需要将条目添加到预先确定的超链接中。例如:

条目 1:2020 年 条目 2:12345

当我点击按钮时它应该打开,比方说,http://www.google.com/2020-12345.html

到目前为止,这是我所在的位置:

# !/usr/bin/python3  

from tkinter import *

top = Tk()

import webbrowser

new = 1
url = "http://www.google.com/e1-e2"

def openweb():
    webbrowser.open(url,new=new)

top.geometry("250x100")

name = Label(top, text="Numbers").place(x=50, y=1)

sbmitbtn = Button(top, text="Submit", command=openweb).place(x=90, y=65)

e1 = Entry(top).place(x=20, y=20)
e2 = Entry(top).place(x=20, y=45)

top.mainloop()

像这样:

from tkinter import *
import webbrowser

# Use {} as a placeholder to allow format() to fill it in later
url_template = "http://www.google.com/{}-{}"

def openweb():
    url = url_template.format(e1.get(), e2.get())
    webbrowser.open(url,new=1)

top = Tk()
top.geometry("250x100")

# Do not use place(). It's very buggy and hard to maintain. Use pack() or grid()
Label(top, text="Numbers").pack()

# You must use 2 lines for named Widgets. You cannot layout on the same line
e1 = Entry(top)
e1.pack()
e2 = Entry(top)
e2.pack()

sbmitbtn = Button(top, text="Submit", command=openweb)
sbmitbtn.pack()

top.mainloop()