Python Tkinter Tutorial | Weapon Wheel Part 1

preview_player
Показать описание
In this video we start creating a weapon wheel in Python Tkinter!

Python Tkinter | Project Tutorials

Python Tkinter | Widget Tutorials

TkDocs

TkDocs | Canvas

TIMESTAMPS
00:00 Create the Root Window
01:30 Create Weapon Wheel Class
02:39 Create Weapon Label
05:06 Create Outer Circle
06:55 Create Weapon Classes
08:42 Create Weapon Circle
Рекомендации по теме
Комментарии
Автор

this was a useful video .
by the way if i have some custom graphics how can i replace those
i am new into coding in py

chaosmachines
Автор

FINAL CODE

from tkinter import *

class Root(Tk):
def __init__(self):
super().__init__()

self.title("Weapon Wheel")

self.weapon_wheel = WeaponWheel(self)

class WeaponWheel(Canvas):
def __init__(self, parent):
super().__init__(parent, width=500, height=500)

self.weapons = [
Sword(),
]

#Canvas Dimensions
can_w = self.winfo_reqwidth()
can_h = self.winfo_reqheight()

#Weapon Label
self.weapon_var = StringVar()


self.weapon_lbl = Label(self,
self.create_window(can_w // 2, can_h // 4 - 25, window=self.weapon_lbl)

#Outer Circle
out_circle_x = can_w // 4
out_circle_y = can_h // 4

out_circle_x1 = can_w - out_circle_x
out_circle_y1 = can_h - out_circle_y

self.out_circle = self.create_oval(out_circle_x, out_circle_y, out_circle_x1, out_circle_y1, tags="out_circle", width=2)

#Weapon Arcs
if len(self.weapons) == 1:
weapon = self.weapons[0]

self.create_image(can_w // 2, can_h // 2, image=weapon.img, tags=weapon.tag + "_img")

self.pack()

class Weapon:
def __init__(self):
self.name = "Weapon"

self.img = None

self.fill_color = "gray"

self.tag = "weapon"

class Sword(Weapon):
def __init__(self):
super().__init__()

self.name = "Sword"

self.img = PhotoImage(file="Sword 50x50.png")

self.fill_color = "red"

self.tag = "sword"

if ___name___ == "__main__":
root = Root()

root.mainloop()

CodeQuest