Launch sites with tkinter – listboxes and simpledialog

This little script can make you open a site

import os
import tkinter as tk
from tkinter import simpledialog


# os.startfile("https://leggi.amazon.it/?asin=B07T3FVKNF")

# Dizionario degli articoli
art_dic = {
"python" : "https://pythonprogramming.altervista.org",
"google" : "www.google.com",
"python_org" : "https://python.org",
}

def art(link):
    os.startfile(art_dic[link])

root = tk.Tk()
root.withdraw()
keys = ""
for k in art_dic:
	keys += k + "\n"

articolo = simpledialog.askstring("Quale articolo vuoi?",keys, parent=root)
art(articolo)
root.mainloop()


Version with listbox

Maybe this one is more practical.

import os
import tkinter as tk
from tkinter import simpledialog


# os.startfile("https://leggi.amazon.it/?asin=B07T3FVKNF")

# Dizionario degli articoli
art_dic = {
"python" : "https://pythonprogramming.altervista.org",
"google" : "www.google.com",
"python_org" : "https://python.org",
}

def art(link):
    os.startfile(art_dic[link])


def run(self):
	art(self.get(self.curselection()))


root = tk.Tk()
root.title("Links launcher")
root.geometry("250x400")
lbx = tk.Listbox(root)
lbx.pack(fill="both", expand=True)
for k in art_dic:
	lbx.insert("end", k)
lbx.bind("<Double-Button>", lambda x: run(lbx))
# articolo = simpledialog.askstring("Quale articolo vuoi?",keys, parent=root)
root.mainloop()
Using a listbox to launch sites

I wanna merge them

Now you can double click on the name or write it
import os
import tkinter as tk
from tkinter import simpledialog


# os.startfile("https://leggi.amazon.it/?asin=B07T3FVKNF")

# Dizionario degli articoli
art_dic = {
"python" : "https://pythonprogramming.altervista.org",
"google" : "www.google.com",
"python_org" : "https://python.org",
}

def art(link):
    os.startfile(art_dic[link])


def run(self):
	art(self.get(self.curselection()))

def popup():
	articolo = simpledialog.askstring("Quale articolo vuoi?","Uno della lista", parent=root)
	art(articolo)

root = tk.Tk()
root.title("Links launcher")
root.geometry("250x400")

#                 MENU
menubar = tk.Menu(root)
menubar.add_command(label="Popup", command=popup)
root.config(menu=menubar)

# ============== gently offered by python_book menu.py


lbx = tk.Listbox(root)
lbx.pack(fill="both", expand=True)
for k in art_dic:
	lbx.insert("end", k)
lbx.bind("<Double-Button>", lambda x: run(lbx))
# articolo = simpledialog.askstring("Quale articolo vuoi?",keys, parent=root)
root.mainloop()

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

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.