Webbrowser meets tkinter part 2

Some changes to the code… 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.

#app tp open chrome

import tkinter as tk
import webbrowser

class Check:
    """ create checkbuttons for links """
    def __init__(self, master, site):
        self.var = tk.IntVar()
        self.site = site
        self = tk.Checkbutton(
            master,
            text = self.site,
            variable = self.var,
            command = self.check).pack()

    def check(self):
        v = self.var.get() # 1 checked 0 unchecked
        if v:
            checked.append(self.site)
        else:
            if self.site in checked:
                checked.remove(self.site)

class App:
    def __init__(self, sites):
        """creates the window"""
        c = []
        master = tk.Tk()
        for site in sites:
            c.append(Check(master, site))
        tk.Button(
            master,
            text = "Launch",
            command = self.start).pack()
        master.mainloop()

    def start(self):
        chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
        w = webbrowser.get(chrome)
        for checked_site in checked:
            w.open(checked_site)

checked = []
app = App([
    "www.gmail.com",
    "https://pythonprogramming.altervista.org/open-sites-with-python-and-webbrowser/"

    ])



Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.