gui.py 927 B

12345678910111213141516171819202122232425262728293031323334353637
  1. '''
  2. Created on 1 mars 2017
  3. @author: olivier.massot
  4. '''
  5. from tkinter import ttk, Tk, Canvas, PhotoImage
  6. from tkinter.constants import CENTER
  7. class Application(ttk.Frame):
  8. def __init__(self, master=None):
  9. super().__init__(master)
  10. self.pack()
  11. self.create_widgets()
  12. def create_widgets(self):
  13. self.logo = PhotoImage(file="logo32.png")
  14. self.canvas = Canvas(self, width=100, height=100)
  15. self.canvas.create_image(20, 20, anchor=CENTER, image=self.logo)
  16. self.canvas.pack()
  17. self.hi_there = ttk.Button(self)
  18. self.hi_there["text"] = "Hello World\n(click me)"
  19. self.hi_there["command"] = self.say_hi
  20. self.hi_there.pack()
  21. self.quit = ttk.Button(self, text="QUIT", command=root.destroy)
  22. self.quit.pack()
  23. def say_hi(self):
  24. print("hi there, everyone!")
  25. root = Tk()
  26. app = Application(master=root)
  27. app.mainloop()