SaveText.Ru

Без имени
  1. import tkinter as tk
  2. from tkinter import filedialog
  3. from tkinter import ttk
  4. # from PIL import Image, ImageTk
  5.  
  6. class Player:
  7.     def __init__(self, name, age, gender):
  8.         self.name = name
  9.         self.age = age
  10.         self.gender = gender
  11.  
  12. class Window:
  13.     def __init__(self, title="Main", width=600, height=600):
  14.         self.width = 600
  15.         self.height = 600
  16.         self.size = f'{width}x{height}'
  17.         self.display = tk.Tk()
  18.         self.display.title(title)
  19.         self.display.geometry(self.size)
  20.         self.display.resizable(0, 0)
  21.  
  22.         self.frames = {'create_player': CreatePlayerFrame(self, "Create New Player")}
  23.         self.activate_frame('create_player')
  24.  
  25.     def start(self):
  26.         self.display.mainloop()
  27.  
  28.     def activate_frame(self, frame_name):
  29.         frame = self.frames[frame_name]
  30.         frame.activate()
  31.         frame.change_title()
  32.  
  33.  
  34.  
  35. class Frame:
  36.     def __init__(self, window, title):
  37.         self.window = window
  38.         self.frame = ttk.Frame(window.display, width=window.width, height=window.height)
  39.         self.title = title
  40.  
  41.         self.style = ttk.Style()
  42.         self.style.configure('TLabel', font=('Calibri', 14))
  43.  
  44.         self.frame.grid(row=0, column=0, sticky='nsew')
  45.  
  46.     def activate(self):
  47.         self.frame.tkraise()
  48.  
  49.     def change_title(self):
  50.         self.frame.master.title(self.title)
  51.  
  52. class CreatePlayerFrame(Frame):
  53.     def __init__(self, window, title):
  54.         super().__init__(window, title)
  55.  
  56.         name_label = ttk.Label(self.frame, text='Player name: ')
  57.         name_label.place(relx=0.01, rely=0.01, anchor=tk.NW)
  58.  
  59.         self.name_field = ttk.Entry(self.frame)
  60.         self.name_field.place(relx=0.01, rely=0.05, anchor=tk.NW)
  61.  
  62.         age_label = ttk.Label(self.frame, text='Player age: ')
  63.         age_label.place(relx=0.01, rely=0.01, anchor=tk.NW)
  64.  
  65.         self.age_field = ttk.Entry(self.frame)
  66.         self.age_field.place(relx=0.01, rely=0.15, anchor=tk.NW)
  67.  
  68.         gender_label = ttk.Label(self.frame, text='Player gender: ')
  69.         gender_label.place(relx=0.01, rely=0.2, anchor=tk.NW)
  70.  
  71.  
  72.         self.gender_field = ttk.Combobox(self.frame, value=['Male', 'Felame'])
  73.         self.gender_field.place(relx=0.01, rely=0.25, anchor=tk.NW)
  74.  
  75.         create_button = ttk.Button(self.frame, text='Create Player', command=self.create_player)
  76.         create_button.place(relx=0.8, rely=0.95, anchor=tk.NW)
  77.  
  78.     def create_player(self):
  79.         player = Player(self.name_field.get(), int(self.age_field.get()),self.gender_field.get())
  80.  
  81.  
  82. if __name__ == '__main__':
  83.     game = Window()
  84.     game.start()

Share with your friends:

Print