I wrote a Python Program the other day, ignore the links, it has a button to go to a test website, a button to quit, and a button to go to a website my parents made, googleaja.com as well as some text. Here it is:
from tkinter import *
from tkinter import ttk
import webbrowser
root = Tk()
def opentestsite():
url = "https://www.example.com"
webbrowser.open(url)
def opengoogleaja():
url="https://googleaja.com/"
webbrowser.open(url)
frm = ttk.Frame(root, padding=10)
frm.grid()
ttk.Label(frm, text="Hello World!").grid(column=0, row=0)
ttk.Button(frm, text="Quit", command=root.destroy).grid(column=1, row=0)
ttk.Label(frm, text="test line 2").grid(column=0, row=1)
ttk.Button(frm, text="Open test website", command=opentestsite).grid(column=1, row=1)
ttk.Button(frm, text="Open googleaja.com", command=opengoogleaja).grid(column=0, row=2)
root.mainloop()
It should work on Python 3.10.8 and maybe above, I used the IDLE editor and installed it from the official Python website I also used the official Tkinter library as well as the new cleaner-looking ttk.
I suggest copy-pasting it straight out and it should work without you having to install anything unless your Python instalment doesn't have tkinter like in Jupyter Notebook where it is not in the initial package due to software limitations.
No comments:
Post a Comment