{"id":2827,"date":"2019-08-11T11:21:29","date_gmt":"2019-08-11T09:21:29","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=2827"},"modified":"2019-08-11T11:21:29","modified_gmt":"2019-08-11T09:21:29","slug":"webbrowser-meets-tkinter-part-2","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/webbrowser-meets-tkinter-part-2\/","title":{"rendered":"Webbrowser meets tkinter part 2"},"content":{"rendered":"<p>Some changes to the code&#8230; and soon we will add the chance to add and delete sites. We talked about this yet and we want to make some other stuff with the code, taking advantage of tkinter checkbuttons.<\/p>\n<pre class=\"lang:default decode:true \">#app tp open chrome\r\n\r\nimport tkinter as tk\r\nimport webbrowser\r\n\r\nclass Check:\r\n    \"\"\" create checkbuttons for links \"\"\"\r\n    def __init__(self, master, site):\r\n        self.var = tk.IntVar()\r\n        self.site = site\r\n        self = tk.Checkbutton(\r\n            master,\r\n            text = self.site,\r\n            variable = self.var,\r\n            command = self.check).pack()\r\n\r\n    def check(self):\r\n        v = self.var.get() # 1 checked 0 unchecked\r\n        if v:\r\n            checked.append(self.site)\r\n        else:\r\n            if self.site in checked:\r\n                checked.remove(self.site)\r\n\r\nclass App:\r\n    def __init__(self, sites):\r\n        \"\"\"creates the window\"\"\"\r\n        c = []\r\n        master = tk.Tk()\r\n        for site in sites:\r\n            c.append(Check(master, site))\r\n        tk.Button(\r\n            master,\r\n            text = \"Launch\",\r\n            command = self.start).pack()\r\n        master.mainloop()\r\n\r\n    def start(self):\r\n        chrome = \"C:\/Program Files (x86)\/Google\/Chrome\/Application\/chrome.exe %s\"\r\n        w = webbrowser.get(chrome)\r\n        for checked_site in checked:\r\n            w.open(checked_site)\r\n\r\nchecked = []\r\napp = App([\r\n    \"www.gmail.com\",\r\n    \"https:\/\/pythonprogramming.altervista.org\/open-sites-with-python-and-webbrowser\/\"\r\n\r\n    ])\r\n\r\n\r\n<\/pre>\n<p><iframe loading=\"lazy\" title=\"Use Chrome with Python to open web pages part 1 and 2\" width=\"747\" height=\"420\" src=\"https:\/\/www.youtube.com\/embed\/C7ItxA3A4Yo?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"Learn to use tkinter checkbutton widgets through a real application to open web pages with webbrowser\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/webbrowser-meets-tkinter-part-2\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":2828,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[500,4,51,45],"class_list":["post-2827","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples","tag-checkbuttons","tag-python","tag-tkinter","tag-webbrowser"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":false,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=2827"}],"version-history":[{"count":1,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2827\/revisions"}],"predecessor-version":[{"id":2829,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2827\/revisions\/2829"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/2828"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=2827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=2827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=2827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}