【问题标题】:Programatically opening URLs in web browser in Python在 Python 中以编程方式在 Web 浏览器中打开 URL
【发布时间】:2011-12-22 20:54:32
【问题描述】:

我有一个 tkinter 脚本。我想知道有没有这样的,当你点击一个按钮时,它会把你带到一个网站

from tkinter import *
app = Tk()
app.geometry("250x400")
app.title("Links")

def Link():
    ?

button1 = Button(app, text = "To a web site.", command = Link)
button1.pack()

app.mainloop()

【问题讨论】:

    标签: python url tkinter hyperlink


    【解决方案1】:

    使用 webbrowser 模块打开<strong>URL</strong>。文档:https://docs.python.org/3/library/webbrowser.html

    # You can use open 
    from webbrowser import open
    def link():
        open('https://www.youtube.com/')
    # You can use open_new_tab
    from webbrowser import open_new_tab
    def link():
        open_new_tab('https://www.youtube.com/')
      
    

    【讨论】:

      【解决方案2】:

      有一个module for that

      import webbrowser
      
      webbrowser.open("http://xkcd.com/353/")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-18
        • 1970-01-01
        • 1970-01-01
        • 2017-11-13
        • 1970-01-01
        • 2018-08-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多