1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| import tkinter as tk
class ToolbarButton(tk.Button):
def __init__(self, master, text, pixelref, *args, **kw):
super(ToolbarButton, self).__init__()
self.master = master
super(ToolbarButton, self).configure(text=text, image=pixelref, height=20, width=20, compound='center')
class MainApplication(tk.Frame):
def __init__(self, parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
# Textframe - ici j'ai juste créé un widget text qui remplit tout l'espace donné par sa frame master, appelée text_frame ci-dessous
self.text_frame = tk.Frame(root, width=600, height=790)
self.text_frame.pack_propagate(False)
self.text_widg = tk.Text(self.text_frame, width=1, height=1)
self.text_widg.pack(expand=True, fill='both')
# Toolbar
self.toolbar = tk.Frame(root)
self.pixel = tk.PhotoImage(width=1, height=1)
self.bold_button = ToolbarButton(self.toolbar, 'B', self.pixel)
self.bold_button.pack(side='left', padx=4)
self.italic_button = ToolbarButton(self.toolbar, 'I', self.pixel)
self.italic_button.pack(side='left', padx=4)
self.underline_button = ToolbarButton(self.toolbar, 'U', self.pixel)
self.underline_button.pack(side='left', padx=4)
# Packing
self.toolbar.pack(side='top', pady=60)
self.text_frame.pack(expand=True)
if __name__ == "__main__":
root = tk.Tk()
MainApplication(root).pack(side="top", fill="both", expand=True)
root.mainloop() |
Partager