Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import pygame
- import tkinter as tk
- from genetic_stuff import *
- class Application(tk.Frame):
- def __init__(self, master=None):
- super().__init__(master=master)
- self.master = master
- self.pack()
- self.setup()
- def setup(self):
- start = tk.Button(self.master, text="Start", command = self.run_simulation)
- self.pause = tk.Button(self.master, text="Pause", command = self.pause_to_resume)
- stop = tk.Button(self.master, text="Stop", command = self.stop_simulation)
- db_create = tk.Button(self.master, text="Create DB")
- db_choose = tk.Button(self.master, text="Choose DB")
- replay = tk.Button(self.master, text="Open Replay")
- load_obs = tk.Button(self.master, text="Open Map")
- default_obs = tk.Button(self.master, text="Use Default")
- editor_obs = tk.Button(self.master, text="Open Editor", command=self.open_editor)
- start.place(x=10, y=10, w=100, h=45)
- self.pause.place(x=125, y=10, w=100, h=45)
- stop.place(x=240, y=10, w=100, h=45)
- db_create.place(x=10, y=70, w=100, h=45)
- db_choose.place(x=125, y=70, w=100, h=45)
- replay.place(x=240, y=70, w=100, h=45)
- load_obs.place(x=10, y=130, w=100, h=45)
- default_obs.place(x=125, y=130, w=100, h=45)
- editor_obs.place(x=240, y=130, w=100, h=45)
- def run_simulation(self):
- self.sim_window = tk.Toplevel(self.master)
- embed = tk.Frame(self.sim_window, width = Main.window_width, height = Main.window_height) #creates embed frame for pygame window
- embed.pack()
- os.environ['SDL_WINDOWID'] = str(embed.winfo_id())
- os.environ['SDL_VIDEODRIVER'] = 'windib'
- run()
- self.sim_window.update()
- def pause_to_resume(self):
- Main.pause_simulation()
- if not Main.running:
- self.pause.config(text="Resume")
- else:
- self.pause.config(text="Pause")
- def stop_simulation(self):
- try:
- Main.exit_flag = True
- self.sim_window.destroy()
- self.master.update()
- except Exception as e:
- print(e, "exception")
- def open_editor(self):
- pygame.init()
- display = pygame.display.set_mode((Main.window_width, Main.window_height))
- display.fill(GREY)
- no_squares = 15
- square_width_x = Main.window_width/no_squares
- square_width_y = Main.window_height/no_squares
- x = 0
- y = 0
- for row in range(no_squares):
- for column in range(no_squares):
- pygame.draw.rect(display, (10, 10, 10) ,(x, y, square_width_x, square_width_y), 1)
- x += square_width_x
- y += square_width_y
- x = 0
- pygame.display.update()
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- exit()
- """window = tk.Toplevel(self.master)
- window.title("a second window")
- window.geometry("1000x70")
- window.resizable(False, False)"""
- root = tk.Tk()
- root.title("A window")
- root.geometry("350x185")
- root.resizable(False, False)
- app = Application(master=root)
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement