def _loadView(self): roomIdField = tk.Entry( self, textvariable=self.chatroom, bg='black', fg='white', highlightcolor='white', justify=tk.CENTER, state=tk.NORMAL if not self._isConnecting else 'readonly', font=_getFont('title2')) roomLabel = tk.Label(self, text='ENTER ROOM ID', bg='black', fg='white', font=_getFont('body')) submit = tk.Button(self, text='CONNECT', bg='black', fg='white', command=self.connectChat, font=_getFont('title2')) roomLabel.place(x=500, y=285, anchor='center') roomIdField.place(x=500, y=235, height=60, anchor='center') submit.place(x=500, y=345, height=60, width='430', anchor='center') roomIdField.focus() roomIdField.bind('<Return>', self.connectChat)
def _loadView(self): icon = tk.PhotoImage(file='assets/elements/CharacterCreatorIcon.png') space = tk.PhotoImage(file='assets/elements/space-top.png') sun = tk.PhotoImage(file='assets/elements/Sun.png') self.icon = icon.subsample(3) self.space = space self.sun = sun.zoom(3) self.create_image(0, 0, image=self.space, anchor=tk.NW) self.create_image(350, 220, image=self.sun) self.create_text(350, 350, font=_getFont('heading-2x'), fill='white', text='YOU JUST CRASHED!') self.create_rectangle(0, 420, 700, 600, fill='#1f1f1f', outline='') self.create_image(350, 480, image=self.icon) self.create_text( 350, 545, font=_getFont('body3'), text='In memory of the brave people in this expedition', fill='white')
def _loadView(self): chatroom = tk.Label( self, text='CHAT DISABLED' if not self.root.enableChat else '{} [{}]'.format(self.root.chat.lobby, self.root.chat.user.name), bg='black', fg='white', font=_getFont('title3')) inputField = tk.Entry(self, textvariable=self.message, bg='black', fg='white', highlightcolor='white', justify=tk.CENTER, font=_getFont('body')) self.messages = tk.Text(self, bg='black', fg='white', borderwidth=0, state=tk.DISABLED, highlightthickness=0, font=_getFont('body')) self.messages.tag_configure('WHITE', foreground='white') self.messages.tag_configure('RED', foreground='red') self.messages.tag_configure('GREEN', foreground='green') self.messages.tag_configure('YELLOW', foreground='yellow') chatroom.place(x=0, y=20, width=300) self.messages.place(x=5, y=60, width=290, height=450) inputField.bind('<Return>', self.sendMessage) inputField.place(x=5, y=530, width=290, height=65) inputField.focus()
def _loadPanel(self): hslider = tk.PhotoImage(file='assets/controls/SliderH.png') if not hasattr(self.root, 'hslider'): self.root.hslider = hslider self.root.addPanel(width=3, height=1, gridPos=(self.x, self.y)) self.root.create_text(210 + PANEL_WIDTH * self.x, Y_OFFSET + 36 + PANEL_HEIGHT * self.y, text=self.label, fill='black', font=_getFont('body')) self.root.create_rectangle(60 + PANEL_WIDTH * self.x, Y_OFFSET + 63 + PANEL_HEIGHT * self.y, 360 + PANEL_WIDTH * self.x, Y_OFFSET + 68 + PANEL_HEIGHT * self.y, fill='black', outline='', tags='{}_GUIDE'.format(self.id)) self.root.create_image(60 + PANEL_WIDTH * self.x, Y_OFFSET + 66 + PANEL_HEIGHT * self.y, image=self.root.hslider, tags=self.id) for i in range(5): self.root.create_text(60 + PANEL_WIDTH * self.x + (i * 75), Y_OFFSET + 101 + PANEL_HEIGHT * self.y, text=str(i), fill='black', font=_getFont('body3')) self.root.tag_bind(self.id, '<B1-Motion>', self.handleHSlider) self.root.tag_bind(self.id, '<ButtonRelease-1>', self.handleHSliderDrop)
def _loadView(self): door_img = tk.PhotoImage(file='assets/elements/exitdoor.png') beam_img = tk.PhotoImage(file='assets/elements/beam.png') beam_toggled_img = tk.PhotoImage( file='assets/elements/beam-toggled.png') floor_img = tk.PhotoImage(file='assets/elements/lobby-floor.png') wallpaper_img = tk.PhotoImage( file='assets/elements/lobby-wallpaper.png') beam_ring = tk.PhotoImage(file='assets/elements/beam-ring.png') player1_img = tk.PhotoImage(file='assets/elements/player.png') self.door = door_img.zoom(3).subsample(2) self.beam = beam_img self.beam_toggled = beam_toggled_img self.floor = floor_img.zoom(3).subsample(2) self.wallpaper = wallpaper_img self.ring = beam_ring.subsample(2) self.avatars = [player1_img] self.avatars = [a.zoom(3).subsample(2) for a in self.avatars] # Wallpaper for y in range(11): for x in range(6): self.create_image(x * 128, y * 30, image=self.wallpaper, anchor=tk.NW) # Floor for x in range(5): self.create_image(x * 192, 310, image=self.floor) # Bind function # self.renderPlayers(1) # hack-ish way self.root.gameData['renderPlayers'] = self.renderPlayers self.create_image(80, 280, image=self.door, tags='DOOR') self.create_image(350, 450, image=self.beam, tags='BEAM') self.create_text(83, 210, font=_getFont('body3'), text='EXIT', fill='white') self.create_text(20, 575, font=_getFont('body3'), text='Waiting Room: {}'.format( self.root.gameData['room']), fill='white', anchor=tk.W) self.tag_bind('BEAM', '<ButtonPress-1>', self.toggleBeam_on) self.tag_bind('BEAM', '<ButtonRelease-1>', self.toggleBeam_off) self.tag_bind('DOOR', '<ButtonPress-1>', self.exitLobby)
def __init__(self, root, text, bg='magenta', command=None): self._canvas = tk.Canvas.__init__(self, root, width=430, height=75, bd=0, highlightthickness=0, bg=bg) normal = tk.PhotoImage(file='assets/ui/button.png') toggled = tk.PhotoImage(file='assets/ui/button-toggle.png') self.normal = normal self.toggled = toggled self.text = text self._command = command self.create_image(-1, -1, image=self.normal, anchor=tk.NW) self.create_text(430 / 2, 75 / 2, font=_getFont('title2'), text=self.text) self.bind('<Button-1>', self._clickOn) self.bind('<ButtonRelease-1>', self._clickOff)
def _loadPanel(self): hswitch_off = tk.PhotoImage(file='assets/ui/horizontalswitch-off.png') hswitch_on = tk.PhotoImage(file='assets/ui/horizontalswitch-on.png') vswitch_off = tk.PhotoImage(file='assets/ui/verticalswitch-off.png') vswitch_on = tk.PhotoImage(file='assets/ui/verticalswitch-on.png') if self.horizontal and not hasattr(self.root, 'hswitch_off'): self.root.hswitch_off = hswitch_off.subsample(2) self.root.hswitch_on = hswitch_on.subsample(2) elif not hasattr(self.root, 'vswitch_off'): self.root.vswitch_off = vswitch_off.subsample(2) self.root.vswitch_on = vswitch_on.subsample(2) self.root.addPanel(width=1, height=1, gridPos=(self.x, self.y)) self.root.create_text( 70 + self.x * PANEL_WIDTH, Y_OFFSET + (45 if self.horizontal else 40) + self.y * PANEL_HEIGHT, text=self.label, fill='black', font=_getFont('body') ) self.root.create_image( 70 + self.x * PANEL_WIDTH, Y_OFFSET + (80 if self.horizontal else 75) + self.y * PANEL_HEIGHT, image=self.root.hswitch_off if self.horizontal else self.root.vswitch_off, tags=self.id ) self.root.tag_bind(self.id, '<Button-1>', self.toggleHSwitch if self.horizontal else self.toggleVSwitch)
def _clickOff(self, event=None): self.create_image(-1, -1, image=self.normal, anchor=tk.NW) self.create_text(430 / 2, 75 / 2, font=_getFont('title2'), text=self.text) if self._command: self._command()
def _loadView(self): inputField = tk.Entry( self, textvariable=self.username, bg='black', fg='white', highlightcolor='white', justify=tk.CENTER, font=_getFont('title2') ) fieldLabel = tk.Label( self, text='ENTER USERNAME', bg='black', fg='white', font=_getFont('body') ) fieldLabel.place(x=500, y=335, anchor='center') inputField.place(x=500, y=285, height=60, anchor='center') inputField.focus() inputField.bind('<Return>', self.setUsername)
def _loadView(self): inputField = tk.Entry( self, textvariable=self.ipaddr, bg='black', fg='white', highlightcolor='white', justify=tk.CENTER, font=_getFont('title2') ) fieldLabel = tk.Label( self, text='ENTER SERVER IP ADDRESS', bg='black', fg='white', font=_getFont('body') ) fieldLabel.place(x=500, y=335, anchor='center') inputField.place(x=500, y=285, height=60, anchor='center') inputField.focus() inputField.bind('<Return>', self.connectToServer)
def _loadView(self): ship = tk.PhotoImage(file='assets/elements/ship-small.png') icon = tk.PhotoImage(file='assets/elements/MedalIcon.png') space = tk.PhotoImage(file='assets/elements/space-top.png') medal = tk.PhotoImage(file='assets/elements/MedalIconFull.png') wreath = tk.PhotoImage(file='assets/elements/Wreath.png') self.ship = ship self.icon = icon.subsample(2) self.space = space self.medal = medal.zoom(3).subsample(2) self.wreath = wreath.subsample(2) self.create_image(0, 0, image=self.space, anchor=tk.NW) self.create_image(-30, 50, image=self.ship, tags='SHIP') self.create_image(350, 220, image=self.wreath) self.create_image(350, 200, image=self.medal) self.create_text(350, 330, font=_getFont('heading-2x'), fill='white', text='CONGRATULATIONS!') self.create_rectangle(0, 420, 700, 600, fill='#1f1f1f', outline='') self.create_image(350, 480, image=self.icon) self.create_text(350, 545, font=_getFont('body3'), text='You have what it takes to be in a spaceteam!', fill='white')
def _loadView(self): ship = tk.PhotoImage(file='assets/elements/ship-small.png') instruction = tk.PhotoImage(file='assets/elements/instruction.png') timer_empty = tk.PhotoImage( file='assets/elements/timer-empty-transparent.png') space = tk.PhotoImage(file='assets/elements/space-top.png') self.ship = ship self.instruction = instruction.zoom(3).subsample(2) self.timer_empty = timer_empty.zoom(3).subsample(2) self.space = space self.create_image(0, 0, image=self.space, anchor=tk.NW) self.create_image(400, 50, image=self.ship, tags='SHIP') # Instruction for distance in range(8): self.create_image(distance * 95, 100, image=self.instruction, anchor=tk.NW) self.create_rectangle(0, 195, 700, 220, fill='green', outline='', tags='TIMER') self.create_image(0, 195, image=self.timer_empty, anchor=tk.NW) self.create_image(480, 195, image=self.timer_empty, anchor=tk.NW) self.create_text(30, 150, text='▶ ' + self.root.gameData['command'], fill='white', font=_getFont('heading'), anchor=tk.W, tags='COMMAND_VIEW')
def _clickOn(self, event=None): self.create_image(-1, -1, image=self.toggled, anchor=tk.NW) self.create_text(430 / 2, 75 / 2, font=_getFont('title2'), text=self.text)
def _loadPanel(self): btn_off = tk.PhotoImage(file='assets/controls/TextButtonOff.png') btn_on = tk.PhotoImage(file='assets/controls/TextButtonOn.png') if not hasattr(self.root, 'btn_off'): self.root.btn_off = btn_off self.root.btn_on = btn_on self.root.addPanel(width=2, height=2, gridPos=(self.x, self.y)) self.root.create_text(145 + PANEL_WIDTH * self.x, Y_OFFSET + 50 + PANEL_HEIGHT * self.y, text=self.label, fill='black', font=_getFont('body')) self.root.create_image(145 + PANEL_WIDTH * self.x, Y_OFFSET + 105 + PANEL_HEIGHT * self.y, image=self.root.btn_off, tags='{}1'.format(self.id)) self.root.create_image(145 + PANEL_WIDTH * self.x, Y_OFFSET + 180 + PANEL_HEIGHT * self.y, image=self.root.btn_off, tags='{}2'.format(self.id)) self.root.create_text(145 + PANEL_WIDTH * self.x, Y_OFFSET + 105 + PANEL_HEIGHT * self.y, text=self.buttons[0], fill='white', font=_getFont('heading-2s'), tags='{}1L'.format(self.id)) self.root.create_text(145 + PANEL_WIDTH * self.x, Y_OFFSET + 180 + PANEL_HEIGHT * self.y, text=self.buttons[1], fill='white', font=_getFont('heading-2s'), tags='{}2L'.format(self.id)) self.root.tag_bind('{}1'.format(self.id), '<Button-1>', lambda _: self.toggleButton('{}1'.format(self.id), True)) self.root.tag_bind('{}1'.format(self.id), '<ButtonRelease-1>', lambda _: self.toggleButton('{}1'.format(self.id), False)) self.root.tag_bind('{}2'.format(self.id), '<Button-1>', lambda _: self.toggleButton('{}2'.format(self.id), True)) self.root.tag_bind('{}2'.format(self.id), '<ButtonRelease-1>', lambda _: self.toggleButton('{}2'.format(self.id), False)) self.root.tag_bind('{}1L'.format(self.id), '<Button-1>', lambda _: self.toggleButton('{}1'.format(self.id), True)) self.root.tag_bind('{}1L'.format(self.id), '<ButtonRelease-1>', lambda _: self.toggleButton('{}1'.format(self.id), False)) self.root.tag_bind('{}2L'.format(self.id), '<Button-1>', lambda _: self.toggleButton('{}2'.format(self.id), True)) self.root.tag_bind('{}2L'.format(self.id), '<ButtonRelease-1>', lambda _: self.toggleButton('{}2'.format(self.id), False))
def _loadPanel(self): box_off = tk.PhotoImage(file='assets/controls/red-off.png') box_on = tk.PhotoImage(file='assets/controls/red-on.png') if not hasattr(self.root, 'box_off'): self.root.box_off = box_off self.root.box_on = box_on text = self.label.split(' ') self.root.addPanel(width=2, height=1, gridPos=(self.x, self.y)) self.root.create_text(65 + PANEL_WIDTH * self.x, Y_OFFSET + 60 + PANEL_HEIGHT * self.y, text=text[0], fill='black', font=_getFont('body')) self.root.create_text(65 + PANEL_WIDTH * self.x, Y_OFFSET + 75 + PANEL_HEIGHT * self.y, text=text[1], fill='black', font=_getFont('body')) self.root.create_image(155 + PANEL_WIDTH * self.x, Y_OFFSET + 64 + PANEL_HEIGHT * self.y, image=self.root.box_off, tags='{}1'.format(self.id)) self.root.create_image(230 + PANEL_WIDTH * self.x, Y_OFFSET + 64 + PANEL_HEIGHT * self.y, image=self.root.box_off, tags='{}2'.format(self.id)) self.root.create_text(155 + PANEL_WIDTH * self.x, Y_OFFSET + 64 + PANEL_HEIGHT * self.y, text='0', fill='white', font=_getFont('heading-2x'), tags='{}1L'.format(self.id)) self.root.create_text(230 + PANEL_WIDTH * self.x, Y_OFFSET + 64 + PANEL_HEIGHT * self.y, text='1', fill='white', font=_getFont('heading-2x'), tags='{}2L'.format(self.id)) self.root.tag_bind( '{}1'.format(self.id), '<Button-1>', lambda _: self.toggleButton('{}1'.format(self.id), True)) self.root.tag_bind( '{}1'.format(self.id), '<ButtonRelease-1>', lambda _: self.toggleButton('{}1'.format(self.id), False)) self.root.tag_bind( '{}2'.format(self.id), '<Button-1>', lambda _: self.toggleButton('{}2'.format(self.id), True)) self.root.tag_bind( '{}2'.format(self.id), '<ButtonRelease-1>', lambda _: self.toggleButton('{}2'.format(self.id), False)) self.root.tag_bind( '{}1L'.format(self.id), '<Button-1>', lambda _: self.toggleButton('{}1'.format(self.id), True)) self.root.tag_bind( '{}1L'.format(self.id), '<ButtonRelease-1>', lambda _: self.toggleButton('{}1'.format(self.id), False)) self.root.tag_bind( '{}2L'.format(self.id), '<Button-1>', lambda _: self.toggleButton('{}2'.format(self.id), True)) self.root.tag_bind( '{}2L'.format(self.id), '<ButtonRelease-1>', lambda _: self.toggleButton('{}2'.format(self.id), False))
def _loadPanel(self): vslider = tk.PhotoImage(file='assets/controls/SliderV.png') if not hasattr(self.root, 'vslider'): self.root.vslider = vslider self.root.addPanel(width=1, height=2, gridPos=(self.x, self.y)) self.root.create_text(70 + PANEL_WIDTH * self.x, Y_OFFSET + 28 + PANEL_HEIGHT * self.y, text=self.label, fill='black', font=_getFont('body')) self.root.create_rectangle(68 + PANEL_WIDTH * self.x, Y_OFFSET + 98 + PANEL_HEIGHT * self.y, 73 + PANEL_WIDTH * self.x, Y_OFFSET + 208 + PANEL_HEIGHT * self.y, fill='black', outline='', tags='{}_GUIDE'.format(self.id)) self.root.create_image(70 + PANEL_WIDTH * self.x, Y_OFFSET + 88 + PANEL_HEIGHT * self.y, image=self.root.vslider, tags=self.id) for i in range(3): self.root.create_text(35 + PANEL_WIDTH * self.x, Y_OFFSET + 88 + PANEL_HEIGHT * self.y + (i * 60), text=str(i), fill='black', font=_getFont('body3')) self.root.tag_bind(self.id, '<B1-Motion>', self.handleVSlider) self.root.tag_bind(self.id, '<ButtonRelease-1>', self.handleVSliderDrop)