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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
import tkinter as tk
from tkinter import ttk, messagebox
from tkinter import *
class window(tk.Tk):
def __init__(self,*args,**kwargs):
tk.Tk.__init__(self,*args,**kwargs)
# Application design
self.title("Visual Tracer")
self.geometry("800x600")
self.iconbitmap("index_FGQ_icon.ico")
menubar = MenuBar(self)
self.config(menu=menubar)
# structure
container = tk.Frame(self)
container.pack(side="top",fill="both",expand=1)
container.grid_rowconfigure(0,weight=1)
container.grid_columnconfigure(1, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
frame = F(container,self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self,cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self,text="Menu")
label.pack(padx=960,pady=10)
button1 = ttk.Button(self, text="Visit Page 1",
command=lambda:controller.show_frame(PageOne))
button1.pack()
button2 = ttk.Button(self, text="Page Two",
command=lambda:controller.show_frame(PageTwo))
button2.pack()
class PageOne(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self,text="PageOne")
label.pack(padx=10,pady=10)
button1 = ttk.Button(self, text="back to home",
command=lambda:controller.show_frame(StartPage))
button1.pack()
button2 = ttk.Button(self, text="Page Two",
command=lambda:controller.show_frame(PageTwo))
button2.pack()
class PageTwo(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self,text="PageTwo")
label.pack(padx=10,pady=10)
button1 = ttk.Button(self, text="back to home",
command=lambda:controller.show_frame(StartPage))
button1.pack()
button2 = ttk.Button(self, text="Page One",
command=lambda:controller.show_frame(PageOne))
button2.pack()
class MenuBar(tk.Menu):
def __init__(self, parent,controller):
tk.Menu.__init__(self, parent)
FileMenu = tk.Menu(self, tearoff=0)
self.add_cascade(label="File",underline=0, menu=FileMenu)
FileMenu.add_command(label="Open file",accelerator="Ctrl+O",compound=tk.LEFT,command=lambda:self.start_new_file())
FileMenu.add_command(label="Open new file",accelerator="Ctrl+N",compound=tk.LEFT)
FileMenu.add_command(label="Save as",accelerator="Ctrl+S", compound=tk.LEFT)
FileMenu.add_command(label="Quit", accelerator="Ctrl+Q",command=self.quit)
EditionMenu = tk.Menu(self, tearoff=0)
self.add_cascade(label="Edition", menu=EditionMenu)
EditionMenu.add_command(label="Copy", accelerator="Ctrl+V", compound=tk.LEFT)
EditionMenu.add_command(label="Paste",accelerator="Ctrl+C", compound=tk.LEFT)
EditionMenu.add_command(label="Cut",accelerator="Ctrl+X", compound=tk.LEFT)
EditionMenu.add_separator()
EditionMenu.add_command(label="Select all",accelerator="Ctrl+A", compound=tk.LEFT)
EditionMenu.add_command(label="Cancel",accelerator="Ctrl+", compound=tk.LEFT)
EditionMenu.add_command(label="Create new window",accelerator="Ctrl+O", compound=tk.LEFT)
EditionMenu.add_command(label="Other short cut",accelerator="Ctrl+H", compound=tk.LEFT)
Setting_simulation = tk.Menu(self, tearoff=0)
self.add_cascade(label="Setting Simulation", menu=Setting_simulation)
Setting_simulation.add_command(label="Weather setting", compound=tk.LEFT)
Setting_simulation.add_command(label="Rocket setting", compound=tk.LEFT)
Setting_simulation.add_command(label="Viewing graphics", compound=tk.LEFT,command=lambda:controller.show_frame(PageOne))
Setting_simulation.add_command(label="Setting live graphic", compound=tk.LEFT)
Simulation = tk.Menu(self,tearoff=0)
self.add_cascade(label="Simulation", menu=Simulation)
Simulation.add_command(label="Graphic",accelerator="Ctrl+G", compound=tk.LEFT,command=lambda:graphic())
Simulation.add_command(label="Live graphic",accelerator="Ctrl+L", compound=tk.LEFT,command=lambda:live_graphic())
Help = tk.Menu(tearoff=0)
self.add_cascade(label="Help", menu=Help)
Help.add_command(label="Documentation", compound=tk.LEFT)
Help.add_command(label="About", compound=tk.LEFT,command=self.Information_about_VisualTracer)
def start_new_file(self):
exec(open("./test_2.py").read())
def Information_about_VisualTracer(self):
messagebox.showinfo("Visual Tracer", "Name: Visual Tracer ©\nVersion: 1.0\nOS: Windows10\nCreation year: 2020")
class graphic(Toplevel):
def __init__(self,*args,**kwargs):
Toplevel.__init__(self)
self.title("Graphic")
self.geometry("800x600")
self.iconbitmap("index_FGQ_icon.ico")
class live_graphic(Toplevel):
def __init__(self,*args,**kwargs):
Toplevel.__init__(self)
self.title("Live Graphic")
self.geometry("800x600")
self.iconbitmap("index_FGQ_icon.ico")
app = window()
app.mainloop() |
Partager