#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2022/04/02 02:05:14 +0900> u""" Hello world in Tkinter. * Windows10 x64 21H2 + Python 2.7.18 32bit + tkinter * Windows10 x64 21H2 + Python 3.9.11 64bit + tkinter """ try: # Python 2.7 import Tkinter as tk except Exception: # Python 3.x import tkinter as tk class App(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.pack() self.lbl = tk.Label(self, text="Hello world").pack() self.btn = tk.Button(self) self.btn["text"] = "Hello", self.btn["command"] = self.say self.btn.pack({"side": "left"}) self.btnquit = tk.Button(self) self.btnquit["text"] = "QUIT" self.btnquit["fg"] = "red" self.btnquit["command"] = self.quit self.btnquit.pack({"side": "left"}) def say(self): print("Hell world ! Tkinter.") def main(): root = tk.Tk() app = App(master=root) app.mainloop() # root.destroy() if __name__ == "__main__": main()