Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
— |
programmazione:python:ttk_hello_world [02/01/2019 - 16:01] (versione attuale) Fabio Di Matteo creata |
||
---|---|---|---|
Linea 1: | Linea 1: | ||
+ | ====== Hello world in Python tkinter (ttk) ====== | ||
+ | Autore: **//Fabio Di Matteo//** \\ Ultima revisione: **// 02/01/2019 - 15:59 //** // // | ||
+ | Un semplice hello world che mostra 2 finestre | ||
+ | |||
+ | <code python> | ||
+ | #!/usr/bin/python3 | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
+ | import tkinter, sys | ||
+ | from tkinter import ttk | ||
+ | |||
+ | class mainWin(): | ||
+ | |||
+ | def __init__(self): | ||
+ | root = tkinter.Tk() | ||
+ | root.geometry("800x600+30+30") | ||
+ | s=tkinter.ttk.Style() | ||
+ | if sys.platform == 'win32': s.theme_use('vista') | ||
+ | if sys.platform == 'linux': s.theme_use('clam') | ||
+ | if sys.platform == 'mac': s.theme_use('acqua') | ||
+ | |||
+ | myLabel = ttk.Label(root, background="red", foreground="white") | ||
+ | myLabel['text']="Pronto" | ||
+ | myLabel['font']="arial 50" | ||
+ | myLabel.pack() | ||
+ | |||
+ | myButton= ttk.Button(root, text="clicca", command=self.onClick) | ||
+ | myButton.pack() | ||
+ | |||
+ | def onClick(self): | ||
+ | print("Clicato") | ||
+ | win1=secondWin() | ||
+ | |||
+ | |||
+ | class secondWin(): | ||
+ | def __init__(self): | ||
+ | root = tkinter.Tk() | ||
+ | root.geometry("800x600+30+30") | ||
+ | |||
+ | myLabel = ttk.Label(root) | ||
+ | myLabel['text']="Seconda finestra" | ||
+ | myLabel['font']="arial 50" | ||
+ | myLabel.pack() | ||
+ | |||
+ | |||
+ | |||
+ | win0=mainWin() | ||
+ | tkinter.mainloop() | ||
+ | |||
+ | </code> |
Il nostro wiki installa solamente cookie tecnici necessari al funzionamento della piattaforma "Dokuwiki". Niente analitics, statistiche, tracciamenti o altro.