CodeQuest
CodeQuest
  • 50
  • 6 457
Python Tkinter Tutorial | How to Run Tkinter on Android
In this video, we'll go over how to run Tkinter on Android devices using the Pydroid 3 app.
Pydroid 3
play.google.com/store/apps/details?id=ru.iiec.pydroid3&hl=en_US&pli=1
Pydroid Repository Plugin
play.google.com/store/apps/details?id=ru.iiec.pydroid3.quickinstallrepo&hl=en_US
GitHub
github.com/BriannaLadson
TIMESTAMPS
00:00 Intro
00:08 Install Pydroid 3
00:27 Install Tkinter
01:02 Run Tkinter
Переглядів: 58

Відео

Python Tkinter Tutorial | How to Draw & Rotate a Cube
Переглядів 25814 днів тому
In this video, we're going to draw and rotate a cube in Python Tkinter! GitHub Code github.com/BriannaLadson/Rotating-Cube/blob/main/main.py Tkinter Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html&si=WA0Bf21oms72yk-Z TIMESTAMPS 00:00 Intro 00:15 Starter Code 00:23 Adding the Canvas 01:07 Drawing the Cube 09:22 Adding X-Axis Rotation 15:55 Adding Y-Axis Rotation 17:58 A...
Python Tkinter Tutorial | Skill Web Part 3
Переглядів 55Місяць тому
We complete our dynamic skill web in Python Tkinter by drawing the graphical representation of the skill levels! Github Code github.com/BriannaLadson/Dynamic-Skill-Web/blob/main/main.py Skill Web Tutorial | Python Tkinter ua-cam.com/play/PLL0F4OU1xPG1dFFSticl9apnxNgbt1cgS.html&si=ycng3d49KsKG87c4 Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html TkDocs t...
Python Tkinter Tutorial | Skill Web Part 2
Переглядів 32Місяць тому
We continue working on the dynamic skill web in Python Tkinter by: -Fixing the Rotation for Odd-Numbered Skill Webs -Drawing Lines from the Center to Each of the Outside Vertices -Displaying Skill Names Around Skill Web Github Code github.com/BriannaLadson/Dynamic-Skill-Web/blob/main/main.py Skill Web Tutorial | Python Tkinter ua-cam.com/play/PLL0F4OU1xPG1dFFSticl9apnxNgbt1cgS.html&si=ycng3d49K...
Python Tkinter Tutorial | Skill Web Part 1
Переглядів 70Місяць тому
This is the start of a new tutorial series where we create a dynamic skill web in Python Tkinter! In this video we display the basic shape of the skill web onto the canvas. Github Code github.com/BriannaLadson/Dynamic-Skill-Web/blob/main/main.py Skill Web Tutorial | Python Tkinter ua-cam.com/play/PLL0F4OU1xPG1dFFSticl9apnxNgbt1cgS.html&si=ycng3d49KsKG87c4 Python Tkinter | Project Tutorials ua-c...
Python Tkinter Tutorial | How to Programmatically Draw Any Regular Polygon
Переглядів 56Місяць тому
In this video I explain the theory and math behind drawing N-gons programmatically! While this knowledge has many applications, I created this video to as a companion video to the upcoming Skill Web tutorial series. In that series we're going to be working with N-gons quite a bit. Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html TkDocs tkdocs.com/shipma...
Python Tkinter Tutorial | Click To Move System
Переглядів 232 місяці тому
In this video we're going to make to implement a basic click-to-move system similar to the one found in games like The Sims and Kenshi! A* Pathfinding | Full Playlist ua-cam.com/play/PLL0F4OU1xPG1JHeh-xeHVUC3_v9iO-11f.html&si=GL2seJ2qVc4pKmKj Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html TkDocs tkdocs.com/shipman/index-2.html TkDocs | Canvas tkdocs.c...
Python Tkinter Tutorial | A Star Pathfinding Part 2
Переглядів 352 місяці тому
In this video we're continuing the A* pathfinding series and actually implementing NPC movement! A* Pathfinding | Full Playlist ua-cam.com/play/PLL0F4OU1xPG1JHeh-xeHVUC3_v9iO-11f.html&si=GL2seJ2qVc4pKmKj Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html TkDocs tkdocs.com/shipman/index-2.html TkDocs | Canvas tkdocs.com/shipman/canvas.html
Python Tkinter Tutorial | A Star Pathfinding Part 1
Переглядів 492 місяці тому
This is the start of a new tutorial series where we implement character pathfinding by using the A* algorithm! In this video we draw the tile map, draw the character, and then highlight the character's randomly selected target tile! A* Pathfinding | Full Playlist ua-cam.com/play/PLL0F4OU1xPG1JHeh-xeHVUC3_v9iO-11f.html&si=GL2seJ2qVc4pKmKj Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4...
Pygame Tutorial | Damage Screen Effect
Переглядів 402 місяці тому
In this video, we create a damage screen effect in Pygame! Pygame Documentation www.pygame.org/docs/
Python Tkinter Tutorial | 2D Grid Based Map Part 4 - Wraparound Map
Переглядів 312 місяці тому
We continue working on our 2D grid-based map in this video by adding in option to toggle wraparound player movement! 2D Grid-Based Map | Full Playlist ua-cam.com/play/PLL0F4OU1xPG1EpS JWM1ZiUc21q8JxEN.html Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html TkDocs tkdocs.com/shipman/index-2.html TkDocs | Canvas tkdocs.com/shipman/canvas.html
Tech Reads | Make Your Own Python Text Adventure by Phillip Johnson
Переглядів 412 місяці тому
If you want to learn Python by making a text adventure game you might want to check out Make Your Own Python Text Adventure by Phillip Johnson! GitHub Repository github.com/Apress/make-your-own-python-text-adventure/tree/master/code Get it on Amazon/Kindle. www.amazon.com/Make-Your-Python-Text-Adventure/dp/1484232305
Python Tkinter Tutorial | 2D Grid-Based Map Part 3
Переглядів 1082 місяці тому
We continue working on our 2D grid-based map in this video by adding in player movement by using the arrow keys! 2D Grid-Based Map | Full Playlist ua-cam.com/play/PLL0F4OU1xPG1EpS JWM1ZiUc21q8JxEN.html Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html Python Tkinter | Widget Tutorials ua-cam.com/play/PLL0F4OU1xPG2BLH7ghyqEL1kyM6mMRgNB.html&si=GlGbgg0Bpyr...
Python Tkinter Tutorial | 2D Grid-Based Map Part 2
Переглядів 362 місяці тому
We continue working on our 2D grid-based map in this video by drawing the map tiles and '@' symbol for the player! 2D Grid-Based Map | Full Playlist ua-cam.com/play/PLL0F4OU1xPG1EpS JWM1ZiUc21q8JxEN.html Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html Python Tkinter | Widget Tutorials ua-cam.com/play/PLL0F4OU1xPG2BLH7ghyqEL1kyM6mMRgNB.html&si=GlGbgg0Bp...
Python Tkinter Tutorial | 2D Grid-Based Map Part 1
Переглядів 852 місяці тому
This video is the start of a new series where we create a 2D grid-based map that the player can move around in by using the arrow keys! 2D Grid-Based Map | Full Playlist ua-cam.com/play/PLL0F4OU1xPG1EpS JWM1ZiUc21q8JxEN.html Python Tkinter | Project Tutorials ua-cam.com/play/PLL0F4OU1xPG19wlaxBLYsRSq_49xqL5ey.html Python Tkinter | Widget Tutorials ua-cam.com/play/PLL0F4OU1xPG2BLH7ghyqEL1kyM6mMR...
Python Tkinter Tutorial | Weapon Wheel Part 3
Переглядів 413 місяці тому
Python Tkinter Tutorial | Weapon Wheel Part 3
Python Tkinter Tutorial | Weapon Wheel Part 2
Переглядів 243 місяці тому
Python Tkinter Tutorial | Weapon Wheel Part 2
Python Tkinter Tutorial | Weapon Wheel Part 1
Переглядів 663 місяці тому
Python Tkinter Tutorial | Weapon Wheel Part 1
Python Tkinter Tutorial | Radial Health Bar
Переглядів 344 місяці тому
Python Tkinter Tutorial | Radial Health Bar
Python Tkinter Tutorial | Health Bar
Переглядів 894 місяці тому
Python Tkinter Tutorial | Health Bar
Python Tkinter Tutorial | Root Window
Переглядів 495 місяців тому
Python Tkinter Tutorial | Root Window
Quest System in Quest | Getting Quest
Переглядів 226 місяців тому
Quest System in Quest | Getting Quest
Quest System in Quest | Quest Status
Переглядів 186 місяців тому
Quest System in Quest | Quest Status
I Made a Perlin Noise Generator in Quest
Переглядів 77 місяців тому
I Made a Perlin Noise Generator in Quest
NPCs in Quest | NPC Movement
Переглядів 32Рік тому
NPCs in Quest | NPC Movement
NPCs in Quest | Downloading NpcLib
Переглядів 31Рік тому
NPCs in Quest | Downloading NpcLib
Making My First Game in Quest | Fantasy Life Devlog 1
Переглядів 30Рік тому
Making My First Game in Quest | Fantasy Life Devlog 1
Need System in Quest | Consuming Food
Переглядів 4Рік тому
Need System in Quest | Consuming Food
Need System in Quest | Food Descriptions
Переглядів 6Рік тому
Need System in Quest | Food Descriptions
Need System in Quest | Generating Food
Переглядів 9Рік тому
Need System in Quest | Generating Food

КОМЕНТАРІ

  • @CodeQuest1
    @CodeQuest1 17 днів тому

    FINAL CODE from tkinter import * import math class Root(Tk): def __init__(self): super().__init__() self.title("3D Rotating Cube") self.state("zoomed") #Canvas self.can = Canvas(self, bg="#FED6D3") self.can.pack(fill=BOTH, expand=1) self.can.update() #Cube Size self.scale = 1500 #Cube Distance from "Camera" self.distance = 8 #Cube Points & Edges self.cube_points = [ [-1, -1, -1], #Vertex 0 [1, -1, -1], #Vertex 1 [1, 1, -1], #Vertex 2 [-1, 1, -1], #Vertex 3 [-1, -1, 1], #Vertex 4 [1, -1, 1], #Vertex 5 [1, 1, 1], #Vertex 6 [-1, 1, 1], #Vertex 7 ] self.cube_edges = [ [0, 1], #Vertex 0 to Vertex 1 [1, 2], #Vertex 1 to Vertex 2 [2, 3], #Vertex 2 to Vertex 3 [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4], [1, 5], [2, 6], [3, 7], ] #Rotation Angles self.angle_x = 0 self.angle_y = 0 self.angle_z = 0 self.animate_cube() def project_point(self, x, y, z): factor = self.scale / (self.distance - z) px = x * factor + self.can.winfo_width() / 2 py = y * factor + self.can.winfo_height() / 2 return int(px), int(py) def rotate_x(self, x, y, z, angle): rad = math.radians(angle) cosa, sina = math.cos(rad), math.sin(rad) y_new = y * cosa - z * sina z_new = y * sina + z * cosa return x, y_new, z_new def rotate_y(self, x, y, z, angle): rad = math.radians(angle) cosa, sina = math.cos(rad), math.sin(rad) x_new = x * cosa + z * sina z_new = -x * sina + z * cosa return x_new, y, z_new def rotate_z(self, x, y, z, angle): rad = math.radians(angle) cosa, sina = math.cos(rad), math.sin(rad) x_new = x * cosa - y * sina y_new = x * sina + y * cosa return x_new, y_new, z def draw_cube(self): self.can.delete("all") rotated_points = [] for x,y,z in self.cube_points: x, y, z = self.rotate_x(x, y, z, self.angle_x) x, y, z = self.rotate_y(x, y, z, self.angle_y) x, y, z = self.rotate_z(x, y, z, self.angle_z) rotated_points.append((x, y, z)) projected_points = [self.project_point(x, y, z) for x, y, z in rotated_points] for edge in self.cube_edges: p1 = projected_points[edge[0]] #Edge/Line Start X,Y p2 = projected_points[edge[1]] #Edge/Line End X,Y self.can.create_line(p1[0], p1[1], p2[0], p2[1], fill="black", width=2) def animate_cube(self): self.angle_x += 1 self.angle_y += 1 self.angle_z += 1 self.draw_cube() self.after(50, self.animate_cube) if ___name___ == "__main__": root = Root() root.mainloop()

  • @w43o21l2f
    @w43o21l2f 17 днів тому

    Nice!

  • @artaoheed
    @artaoheed Місяць тому

    Thank you for sharing the code

  • @CodeQuest1
    @CodeQuest1 Місяць тому

    FINAL CODE from tkinter import * import math import random class Root(Tk): def __init__(self): super().__init__() self.title("Skill Web") self.state("zoomed") self.skill_web = SkillWeb(self) self.skill_web.pack(fill=BOTH, expand=1) self.skill_web.draw() class SkillWeb(Canvas): def __init__(self, parent): super().__init__(parent, bg="#FED6D3") #Must Have at least 3 Skills! self.skills = { "Strength": random.randint(0, 100), "Intelligence": random.randint(0, 100), "Willpower": random.randint(0, 100), "Agility": random.randint(0, 100), "Speed": random.randint(0, 100), #"Endurance": random.randint(0, 100), #"Personality": random.randint(0, 100), #"Luck": random.randint(0, 100), } #Imaginary Circle self.center_x = self.winfo_width() / 2 self.center_y = self.winfo_height() / 2 #Determines Size of 1st Layer self.outer_radius = 200 #Determines Size of Last Layer self.inner_radius = 50 #Number of Layers. Must Be at Least 2! self.layers = 5 #N-gon (#vertices, skills, edges) self.n_gon = len(self.skills) #Vertex Angle self.vertex_angle = 2 * math.pi / self.n_gon #Rotates Skill Web self.offset = (math.pi / 2) * -1 def draw(self): #Update Canvas self.update() #Imaginary Circle Center self.center_x = self.winfo_width() / 2 self.center_y = self.winfo_height() / 2 #Space Between Each Layer decrement = (self.outer_radius - self.inner_radius) / (self.layers - 1) #Skills skill_names = list(self.skills.keys()) skill_levels = list(self.skills.values()) #Iterate THrough Each Layer for layer in range(self.layers): #Calculate Layer Radius cur_radius = self.outer_radius - layer * decrement #List to Store Vertices vertices = [] #Calculate Vertices for i in range(self.n_gon): #Calculate Angle for Current Vertex angle = self.offset + i * self.vertex_angle #Calculate Vertex Coordinates x = self.center_x + cur_radius * math.cos(angle) y = self.center_y + cur_radius * math.sin(angle) #Append Coordinates to Vertices List vertices.append([x, y]) #Draw Line Between Vertices for Current Layer self.create_polygon(vertices, fill="", outline="black", width=3) #Draw Lines from Center to Outside Vertices if layer == 0: for j in range(self.n_gon): x, y = vertices[j] self.create_line(x, y, self.center_x, self.center_y, width=3) """Display Skill Names""" #Skill Name Radius lbl_r = self.outer_radius + 30 #Skill Name Angle angle = self.offset + j * self.vertex_angle #Calculate Skill Name X,Y lbl_x = self.center_x + lbl_r * math.cos(angle) lbl_y = self.center_y + lbl_r * math.sin(angle) #Display Skill Name self.create_text(lbl_x, lbl_y, text=skill_names[j]) """Calculate Skill Level Vertices""" #List to Store Skill Vertices skill_vertices = [] #Iterate through Skill Levels w/ Index for l, level in enumerate(skill_levels): max_level = min(level, 100) if level == 0: r = 0 else: normalized_level = (max_level - 1) / (100 - 1) r = self.inner_radius + normalized_level * (self.outer_radius - self.inner_radius) angle = self.offset + l * self.vertex_angle x = self.center_x + r * math.cos(angle) y = self.center_y + r * math.sin(angle) skill_vertices.append([x, y]) #Fill Shape Formed by Skill Vertices coordinates = [coords for vertex in skill_vertices for coords in vertex] self.create_polygon(coordinates, fill="#9D8A88", outline="black", width=2) #Draw Skill Vertices for x, y in skill_vertices: self.create_oval(x - 10, y - 10, x + 10, y + 10, fill="#9D8A88", outline="black", width=2) if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 Місяць тому

    FINAL CODE from tkinter import * import math import random class Root(Tk): def __init__(self): super().__init__() self.title("Skill Web") self.state("zoomed") self.skill_web = SkillWeb(self) self.skill_web.pack(fill=BOTH, expand=1) self.skill_web.draw() class SkillWeb(Canvas): def __init__(self, parent): super().__init__(parent, bg="#FED6D3") #Must Have at least 3 Skills! self.skills = { "Strength": random.randint(0, 100), "Intelligence": random.randint(0, 100), "Willpower": random.randint(0, 100), "Agility": random.randint(0, 100), "Speed": random.randint(0, 100), #"Endurance": random.randint(0, 100), #"Personality": random.randint(0, 100), #"Luck": random.randint(0, 100), } #Imaginary Circle self.center_x = self.winfo_width() / 2 self.center_y = self.winfo_height() / 2 #Determines Size of 1st Layer self.outer_radius = 200 #Determines Size of Last Layer self.inner_radius = 50 #Number of Layers. Must Be at Least 2! self.layers = 5 #N-gon (#vertices, skills, edges) self.n_gon = len(self.skills) #Vertex Angle self.vertex_angle = 2 * math.pi / self.n_gon #Rotates Skill Web self.offset = (math.pi / 2) * -1 def draw(self): #Update Canvas self.update() #Imaginary Circle Center self.center_x = self.winfo_width() / 2 self.center_y = self.winfo_height() / 2 #Space Between Each Layer decrement = (self.outer_radius - self.inner_radius) / (self.layers - 1) #Skills skill_names = list(self.skills.keys()) #Iterate THrough Each Layer for layer in range(self.layers): #Calculate Layer Radius cur_radius = self.outer_radius - layer * decrement #List to Store Vertices vertices = [] #Calculate Vertices for i in range(self.n_gon): #Calculate Angle for Current Vertex angle = self.offset + i * self.vertex_angle #Calculate Vertex Coordinates x = self.center_x + cur_radius * math.cos(angle) y = self.center_y + cur_radius * math.sin(angle) #Append Coordinates to Vertices List vertices.append([x, y]) #Draw Line Between Vertices for Current Layer self.create_polygon(vertices, fill="", outline="black", width=3) #Draw Lines from Center to Outside Vertices if layer == 0: for j in range(self.n_gon): x, y = vertices[j] self.create_line(x, y, self.center_x, self.center_y, width=3) """Display Skill Names""" #Skill Name Radius lbl_r = self.outer_radius + 30 #Skill Name Angle angle = self.offset + j * self.vertex_angle #Calculate Skill Name X,Y lbl_x = self.center_x + lbl_r * math.cos(angle) lbl_y = self.center_y + lbl_r * math.sin(angle) #Display Skill Name self.create_text(lbl_x, lbl_y, text=skill_names[j]) if ___name___ == "__main__": root = Root() root.mainloop()

  • @AnthonyRobinson-d4c
    @AnthonyRobinson-d4c Місяць тому

    Thanks for the breakdown! Could you help me with something unrelated: I have a SafePal wallet with USDT, and I have the seed phrase. (alarm fetch churn bridge exercise tape speak race clerk couch crater letter). What's the best way to send them to Binance?

  • @CodeQuest1
    @CodeQuest1 Місяць тому

    FINAL CODE from tkinter import * import math import random class Root(Tk): def __init__(self): super().__init__() self.title("Skill Web") self.state("zoomed") self.skill_web = SkillWeb(self) self.skill_web.pack(fill=BOTH, expand=1) self.skill_web.draw() class SkillWeb(Canvas): def __init__(self, parent): super().__init__(parent, bg="#FED6D3") #Must Have at least 3 Skills! self.skills = { "Strength": random.randint(0, 100), "Intelligence": random.randint(0, 100), "Willpower": random.randint(0, 100), "Agility": random.randint(0, 100), "Speed": random.randint(0, 100), "Endurance": random.randint(0, 100), "Personality": random.randint(0, 100), "Luck": random.randint(0, 100), } #Imaginary Circle self.center_x = self.winfo_width() / 2 self.center_y = self.winfo_height() / 2 #Determines Size of 1st Layer self.outer_radius = 200 #Determines Size of Last Layer self.inner_radius = 50 #Number of Layers. Must Be at Least 2! self.layers = 5 #N-gon (#vertices, skills, edges) self.n_gon = len(self.skills) #Vertex Angle self.vertex_angle = 2 * math.pi / self.n_gon def draw(self): #Update Canvas self.update() #Imaginary Circle Center self.center_x = self.winfo_width() / 2 self.center_y = self.winfo_height() / 2 #Space Between Each Layer decrement = (self.outer_radius - self.inner_radius) / (self.layers - 1) #Iterate THrough Each Layer for layer in range(self.layers): #Calculate Layer Radius cur_radius = self.outer_radius - layer * decrement #List to Store Vertices vertices = [] #Calculate Vertices for i in range(self.n_gon): #Calculate Angle for Current Vertex angle = i * self.vertex_angle #Calculate Vertex Coordinates x = self.center_x + cur_radius * math.cos(angle) y = self.center_y + cur_radius * math.sin(angle) #Append Coordinates to Vertices List vertices.append([x, y]) #Draw Line Between Vertices for Current Layer self.create_polygon(vertices, fill="", outline="black", width=3) if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 Місяць тому

    FINAL CODE from tkinter import * import math class Root(Tk): def __init__(self): super().__init__() self.title("N-gon Drawing") #Canvas self.can = Canvas(self, width=500, height=500) self.can.pack(fill=BOTH, expand=1) self.can.update() can_w = self.can.winfo_width() can_h = self.can.winfo_height() #Imaginary Circle self.center_x = can_w / 2 self.center_y = can_h / 2 self.radius = 200 #N-gon self.n_gon = 3 #Vertex Angle self.vertex_angle = 2 * math.pi / self.n_gon #Offset self.offset = (math.pi / 2) * -1 self.draw_ngon() def draw_ngon(self): vertices = [] for i in range(self.n_gon): angle = self.offset + i * self.vertex_angle x = self.center_x + self.radius * math.cos(angle) y = self.center_y + self.radius * math.sin(angle) vertices.extend([x,y]) self.can.create_polygon(vertices, fill="", outline="black") if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 2 місяці тому

    FINAL CODE from tkinter import * import random import time import math import threading class Root(Tk): def __init__(self): super().__init__() self.title("Click 2 Move") self.state("zoomed") self.map_size = 20 self.npc_x = 0 self.npc_y = 0 self.target_x = None self.target_y = None self.directions = { "north": [0, -1], "northwest": [-1, -1], "northeast": [1, -1], "south": [0, 1], "southwest": [-1, 1], "southeast": [1, 1], "west": [-1, 0], "east": [1, 0], } self.can = Canvas(self, bg="#FED6D3") self.can.pack(fill=BOTH, expand=1) """ self.play_var = BooleanVar() self.play_var.set(False) self.play_btn = Button(self, text="Play", command=self.toggle) self.play_btn.pack() """ self.draw_map() self.draw_npc() #self.random_target() self.can.bind("<Button-1>", self.click_target) threading.Thread(target=self.move_ai).start() def draw_map(self): map_size = self.map_size can = self.can can.update() can_w = self.can.winfo_width() can_h = self.can.winfo_height() tile_w = can_w / map_size tile_h = can_h / map_size for row in range(0, map_size): for col in range(0, map_size): x = col * tile_w y = row * tile_h x1 = x + tile_w y1 = y + tile_h can.create_rectangle(x, y, x1, y1) def draw_npc(self): tile_w = self.can.winfo_width() / self.map_size tile_h = self.can.winfo_height() / self.map_size scale = .5 diameter = min(tile_w, tile_h) * scale x = self.npc_x * tile_w + (tile_w - diameter) / 2 y = self.npc_y * tile_h + (tile_h - diameter) / 2 x1 = x + diameter y1 = y + diameter self.npc = self.can.create_oval(x, y, x1, y1, fill="#9D8A88", width=2) def random_target(self): self.target_x = random.randint(0, self.map_size - 1) self.target_y = random.randint(0, self.map_size - 1) tile_w = self.can.winfo_width() / self.map_size tile_h = self.can.winfo_height() / self.map_size x = self.target_x * tile_w y = self.target_y * tile_h x1 = x + tile_w y1 = y + tile_h try: self.can.delete(self.target_rect) except AttributeError: pass self.target_rect = self.can.create_rectangle(x, y, x1, y1, fill="red") def toggle(self): if not self.play_var.get(): self.play_var.set(True) self.play_btn.config(text="Pause") threading.Thread(target=self.move_ai).start() else: self.play_var.set(False) self.play_btn.config(text="Play") def move_ai(self): while True: if not self.target_x == None and not self.target_y == None: #NPC is at target tile. if self.npc_x == self.target_x and self.npc_y == self.target_y: self.target_x = None self.target_y = None else: distances = {} nx = self.npc_x ny = self.npc_y tx = self.target_x ty = self.target_y for dir in self.directions: coors = self.directions[dir] cx = coors[0] cy = coors[1] #Surrounding Tile dx = nx + cx dy = ny + cy distance = math.dist([dx, dy], [tx, ty]) distances[dir] = distance next_dir = self.get_shortest_distance(distances) coors = self.directions[next_dir] self.move(coors[0], coors[1]) time.sleep(3) def get_shortest_distance(self, distances): return min(distances, key=distances.get) def move(self, x, y): self.npc_x += x self.npc_y += y self.can.delete(self.npc) self.draw_npc() def click_target(self, event): #Get Tile Based on Click tile_w = self.can.winfo_width() / self.map_size tile_h = self.can.winfo_height() / self.map_size self.target_x = event.x // tile_w self.target_y = event.y // tile_h #Draw Target Rect x = self.target_x * tile_w y = self.target_y * tile_h x1 = x + tile_w y1 = y + tile_h try: self.can.delete(self.target_rect) except AttributeError: pass self.target_rect = self.can.create_rectangle(x, y, x1, y1, fill="red") if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 2 місяці тому

    FINAL CODE from tkinter import * import random import time import math import threading class Root(Tk): def __init__(self): super().__init__() self.title("A*") self.state("zoomed") self.map_size = 20 self.npc_x = 0 self.npc_y = 0 self.directions = { "north": [0, -1], "northwest": [-1, -1], "northeast": [1, -1], "south": [0, 1], "southwest": [-1, 1], "southeast": [1, 1], "west": [-1, 0], "east": [1, 0], } self.can = Canvas(self, bg="#FED6D3") self.can.pack(fill=BOTH, expand=1) self.play_var = BooleanVar() self.play_var.set(False) self.play_btn = Button(self, text="Play", command=self.toggle) self.play_btn.pack() self.draw_map() self.draw_npc() self.random_target() def draw_map(self): map_size = self.map_size can = self.can can.update() can_w = self.can.winfo_width() can_h = self.can.winfo_height() tile_w = can_w / map_size tile_h = can_h / map_size for row in range(0, map_size): for col in range(0, map_size): x = col * tile_w y = row * tile_h x1 = x + tile_w y1 = y + tile_h can.create_rectangle(x, y, x1, y1) def draw_npc(self): tile_w = self.can.winfo_width() / self.map_size tile_h = self.can.winfo_height() / self.map_size scale = .5 diameter = min(tile_w, tile_h) * scale x = self.npc_x * tile_w + (tile_w - diameter) / 2 y = self.npc_y * tile_h + (tile_h - diameter) / 2 x1 = x + diameter y1 = y + diameter self.npc = self.can.create_oval(x, y, x1, y1, fill="#9D8A88", width=2) def random_target(self): self.target_x = random.randint(0, self.map_size - 1) self.target_y = random.randint(0, self.map_size - 1) tile_w = self.can.winfo_width() / self.map_size tile_h = self.can.winfo_height() / self.map_size x = self.target_x * tile_w y = self.target_y * tile_h x1 = x + tile_w y1 = y + tile_h try: self.can.delete(self.target_rect) except AttributeError: pass self.target_rect = self.can.create_rectangle(x, y, x1, y1, fill="red") def toggle(self): if not self.play_var.get(): self.play_var.set(True) self.play_btn.config(text="Pause") threading.Thread(target=self.move_ai).start() else: self.play_var.set(False) self.play_btn.config(text="Play") def move_ai(self): while self.play_var.get(): #NPC is at target tile. if self.npc_x == self.target_x and self.npc_y == self.target_y: self.random_target() else: distances = {} nx = self.npc_x ny = self.npc_y tx = self.target_x ty = self.target_y for dir in self.directions: coors = self.directions[dir] cx = coors[0] cy = coors[1] #Surrounding Tile dx = nx + cx dy = ny + cy distance = math.dist([dx, dy], [tx, ty]) distances[dir] = distance next_dir = self.get_shortest_distance(distances) coors = self.directions[next_dir] self.move(coors[0], coors[1]) time.sleep(1) def get_shortest_distance(self, distances): return min(distances, key=distances.get) def move(self, x, y): self.npc_x += x self.npc_y += y self.can.delete(self.npc) self.draw_npc() if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 2 місяці тому

    FINAL CODE from tkinter import * import random class Root(Tk): def __init__(self): super().__init__() self.title("A*") self.state("zoomed") self.map_size = 20 self.npc_x = 0 self.npc_y = 0 self.can = Canvas(self, bg="#FED6D3") self.can.pack(fill=BOTH, expand=1) self.draw_map() self.draw_npc() self.random_target() def draw_map(self): map_size = self.map_size can = self.can can.update() can_w = self.can.winfo_width() can_h = self.can.winfo_height() tile_w = can_w / map_size tile_h = can_h / map_size for row in range(0, map_size): for col in range(0, map_size): x = col * tile_w y = row * tile_h x1 = x + tile_w y1 = y + tile_h can.create_rectangle(x, y, x1, y1) def draw_npc(self): tile_w = self.can.winfo_width() / self.map_size tile_h = self.can.winfo_height() / self.map_size scale = .5 diameter = min(tile_w, tile_h) * scale x = self.npc_x * tile_w + (tile_w - diameter) / 2 y = self.npc_y * tile_h + (tile_h - diameter) / 2 x1 = x + diameter y1 = y + diameter self.npc = self.can.create_oval(x, y, x1, y1, fill="#9D8A88", width=2) def random_target(self): self.target_x = random.randint(0, self.map_size - 1) self.target_y = random.randint(0, self.map_size - 1) tile_w = self.can.winfo_width() / self.map_size tile_h = self.can.winfo_height() / self.map_size x = self.target_x * tile_w y = self.target_y * tile_h x1 = x + tile_w y1 = y + tile_h try: self.can.delete(self.target_rect) except AttributeError: pass self.target_rect = self.can.create_rectangle(x, y, x1, y1, fill="red") if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 2 місяці тому

    FINAL CODE import pygame pygame.init() #Constants WIDTH, HEIGHT = 800, 600 DAMAGE_COLOR = (255, 0, 0) DAMAGE_ALPHA = 255 DAMAGE_FADE_RATE = 5 #Screen screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Damage Screen Effect") #Surface damage_overlay = pygame.Surface((WIDTH, HEIGHT)) damage_overlay.fill(DAMAGE_COLOR) damage_overlay.set_alpha(0) #Loop running = True taking_damage = False while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: taking_damage = True DAMAGE_ALPHA = 255 if taking_damage: damage_overlay.set_alpha(DAMAGE_ALPHA) DAMAGE_ALPHA = max(0, DAMAGE_ALPHA - DAMAGE_FADE_RATE) screen.fill((255, 255, 255)) if taking_damage: screen.blit(damage_overlay, (0, 0)) #Update Display pygame.display.flip() #Control Frame Rate pygame.time.delay(60)

  • @CodeQuest1
    @CodeQuest1 2 місяці тому

    FINAL CODE from tkinter import * class Root(Tk): def __init__(self): super().__init__() self.title("2D Grid Map") self.state("zoomed") #Player Coords self.player_x = 3 self.player_y = 7 #Control Frame self.control_fr = Frame(self) self.control_fr.pack(side=LEFT, fill=Y) #Control - Title self.control_lbl = Label(self.control_fr, text="Controls") self.control_lbl.grid(row=0, column=0, columnspan=2) #Control - World Size self.world_size_lbl = Label(self.control_fr, text="World Size:") self.world_size_lbl.grid(row=1, column=0) self.world_size_var = StringVar() self.world_size_var.set("10") self.world_size_var.trace_add("write", self.trace) self.world_size_ent = Entry(self.control_fr, textvariable=self.world_size_var) self.world_size_ent.grid(row=1, column=1) #Control - Wraparound self.wraparound_var = IntVar() self.wraparound_cb = Checkbutton(self.control_fr, text="Wraparound", variable=self.wraparound_var) self.wraparound_cb.grid(row=2, column=0, columnspan=2) #Control - Update self.update_btn = Button(self.control_fr, text="Update", command=self.update_map) self.update_btn.grid(row=3, column=0, columnspan=2) #Map Frame self.map_fr = Frame(self) self.map_fr.pack(side=LEFT, fill=BOTH, expand=1) #Map - Location Label self.loc_var = StringVar() self.loc_var.set("Location: ") self.loc_lbl = Label(self.map_fr, textvariable=self.loc_var) self.loc_lbl.pack() #Map - Canvas self.map_can = Canvas(self.map_fr, bg="gray") self.map_can.pack(fill=BOTH, expand=1) #Bindings self.bind("<Up>", lambda e: self.move_player(e, -1, 0)) self.bind("<Down>", lambda e: self.move_player(e, 1, 0)) self.bind("<Left>", lambda e: self.move_player(e, 0, -1)) self.bind("<Right>", lambda e: self.move_player(e, 0, 1)) self.trace() def trace(self, *args): try: world_size = int(self.world_size_var.get()) if world_size < 1: raise ValueError else: self.update_btn.config(state=NORMAL) except ValueError: self.update_btn.config(state=DISABLED) def update_map(self): self.update_loc() #Draw Tiles can = self.map_can can.delete("all") world_size = int(self.world_size_var.get()) can_w = can.winfo_width() can_h = can.winfo_height() tile_w = can_w / world_size tile_h = can_h / world_size for row in range(0, world_size): for col in range(0, world_size): x = col * tile_w y = row * tile_h x1 = x + tile_w y1 = y + tile_h can.create_rectangle(x, y, x1, y1) if row == self.player_x and col == self.player_y: self.draw_player(x, y, x1, y1) def update_loc(self): px = str(self.player_x) py = str(self.player_y) self.loc_var.set("Location: {},{}".format(px, py)) def draw_player(self, x, y, x1, y1): #Calc Midpoint mx = (x + x1) / 2 my = (y + y1) / 2 self.map_can.create_text(mx, my, text='@') def move_player(self, e, x, y): try: world_size = int(self.world_size_var.get()) self.player_x += x self.player_y += y if self.wraparound_var.get() == 0: if self.player_x < 0: self.player_x = 0 elif self.player_x > world_size - 1: self.player_x = world_size - 1 if self.player_y < 0: self.player_y = 0 elif self.player_y > world_size - 1: self.player_y = world_size - 1 else: if self.player_x < 0: self.player_x = world_size - 1 elif self.player_x > world_size - 1: self.player_x = 0 if self.player_y < 0: self.player_y = world_size - 1 elif self.player_y > world_size - 1: self.player_y = 0 self.update_map() except ValueError: pass if ___name___ == "__main__": root = Root() root.mainloop()

  • @ardhenismuhammadaflah7818
    @ardhenismuhammadaflah7818 2 місяці тому

    Nice tutorial btw

  • @ardhenismuhammadaflah7818
    @ardhenismuhammadaflah7818 2 місяці тому

    Can you update more bro? I need this type of contenr

    • @CodeQuest1
      @CodeQuest1 2 місяці тому

      Sure, is there something in particular you're looking for?

  • @ardhenismuhammadaflah7818
    @ardhenismuhammadaflah7818 2 місяці тому

    Keep it up!

  • @CodeQuest1
    @CodeQuest1 2 місяці тому

    FINAL CODE from tkinter import * class Root(Tk): def __init__(self): super().__init__() self.title("2D Grid Map") self.state("zoomed") #Player Coords self.player_x = 3 self.player_y = 7 #Control Frame self.control_fr = Frame(self) self.control_fr.pack(side=LEFT, fill=Y) #Control - Title self.control_lbl = Label(self.control_fr, text="Controls") self.control_lbl.grid(row=0, column=0, columnspan=2) #Control - World Size self.world_size_lbl = Label(self.control_fr, text="World Size:") self.world_size_lbl.grid(row=1, column=0) self.world_size_var = StringVar() self.world_size_var.set("10") self.world_size_var.trace_add("write", self.trace) self.world_size_ent = Entry(self.control_fr, textvariable=self.world_size_var) self.world_size_ent.grid(row=1, column=1) #Control - Update self.update_btn = Button(self.control_fr, text="Update", command=self.update_map) self.update_btn.grid(row=2, column=0, columnspan=2) #Map Frame self.map_fr = Frame(self) self.map_fr.pack(side=LEFT, fill=BOTH, expand=1) #Map - Location Label self.loc_var = StringVar() self.loc_var.set("Location: ") self.loc_lbl = Label(self.map_fr, textvariable=self.loc_var) self.loc_lbl.pack() #Map - Canvas self.map_can = Canvas(self.map_fr, bg="gray") self.map_can.pack(fill=BOTH, expand=1) #Bindings self.bind("<Up>", lambda e: self.move_player(e, -1, 0)) self.bind("<Down>", lambda e: self.move_player(e, 1, 0)) self.bind("<Left>", lambda e: self.move_player(e, 0, -1)) self.bind("<Right>", lambda e: self.move_player(e, 0, 1)) self.trace() def trace(self, *args): try: world_size = int(self.world_size_var.get()) if world_size < 1: raise ValueError else: self.update_btn.config(state=NORMAL) except ValueError: self.update_btn.config(state=DISABLED) def update_map(self): self.update_loc() #Draw Tiles can = self.map_can can.delete("all") world_size = int(self.world_size_var.get()) can_w = can.winfo_width() can_h = can.winfo_height() tile_w = can_w / world_size tile_h = can_h / world_size for row in range(0, world_size): for col in range(0, world_size): x = col * tile_w y = row * tile_h x1 = x + tile_w y1 = y + tile_h can.create_rectangle(x, y, x1, y1) if row == self.player_x and col == self.player_y: self.draw_player(x, y, x1, y1) def update_loc(self): px = str(self.player_x) py = str(self.player_y) self.loc_var.set("Location: {},{}".format(px, py)) def draw_player(self, x, y, x1, y1): #Calc Midpoint mx = (x + x1) / 2 my = (y + y1) / 2 self.map_can.create_text(mx, my, text='@') def move_player(self, e, x, y): try: world_size = int(self.world_size_var.get()) self.player_x += x self.player_y += y if self.player_x < 0: self.player_x = 0 elif self.player_x > world_size - 1: self.player_x = world_size - 1 if self.player_y < 0: self.player_y = 0 elif self.player_y > world_size - 1: self.player_y = world_size - 1 self.update_map() except ValueError: pass if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 2 місяці тому

    FINAL CODE from tkinter import * class Root(Tk): def __init__(self): super().__init__() self.title("2D Grid Map") self.state("zoomed") #Player Coords self.player_x = 3 self.player_y = 7 #Control Frame self.control_fr = Frame(self) self.control_fr.pack(side=LEFT, fill=Y) #Control - Title self.control_lbl = Label(self.control_fr, text="Controls") self.control_lbl.grid(row=0, column=0, columnspan=2) #Control - World Size self.world_size_lbl = Label(self.control_fr, text="World Size:") self.world_size_lbl.grid(row=1, column=0) self.world_size_var = StringVar() self.world_size_var.set("10") self.world_size_var.trace_add("write", self.trace) self.world_size_ent = Entry(self.control_fr, textvariable=self.world_size_var) self.world_size_ent.grid(row=1, column=1) #Control - Update self.update_btn = Button(self.control_fr, text="Update", command=self.update_map) self.update_btn.grid(row=2, column=0, columnspan=2) #Map Frame self.map_fr = Frame(self) self.map_fr.pack(side=LEFT, fill=BOTH, expand=1) #Map - Location Label self.loc_var = StringVar() self.loc_var.set("Location: ") self.loc_lbl = Label(self.map_fr, textvariable=self.loc_var) self.loc_lbl.pack() #Map - Canvas self.map_can = Canvas(self.map_fr, bg="gray") self.map_can.pack(fill=BOTH, expand=1) self.trace() def trace(self, *args): try: world_size = int(self.world_size_var.get()) if world_size < 1: raise ValueError else: self.update_btn.config(state=NORMAL) except ValueError: self.update_btn.config(state=DISABLED) def update_map(self): self.update_loc() #Draw Tiles can = self.map_can can.delete("all") world_size = int(self.world_size_var.get()) can_w = can.winfo_width() can_h = can.winfo_height() tile_w = can_w / world_size tile_h = can_h / world_size for row in range(0, world_size): for col in range(0, world_size): x = col * tile_w y = row * tile_h x1 = x + tile_w y1 = y + tile_h can.create_rectangle(x, y, x1, y1) if row == self.player_x and col == self.player_y: self.draw_player(x, y, x1, y1) def update_loc(self): px = str(self.player_x) py = str(self.player_y) self.loc_var.set("Location: {},{}".format(px, py)) def draw_player(self, x, y, x1, y1): #Calc Midpoint mx = (x + x1) / 2 my = (y + y1) / 2 self.map_can.create_text(mx, my, text='@') if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 3 місяці тому

    FINAL CODE from tkinter import * class Root(Tk): def __init__(self): super().__init__() self.title("2D Grid Map") self.state("zoomed") #Control Frame self.control_fr = Frame(self) self.control_fr.pack(side=LEFT, fill=Y) #Control - Title self.control_lbl = Label(self.control_fr, text="Controls") self.control_lbl.grid(row=0, column=0, columnspan=2) #Control - World Size self.world_size_lbl = Label(self.control_fr, text="World Size:") self.world_size_lbl.grid(row=1, column=0) self.world_size_var = StringVar() self.world_size_var.set("10") self.world_size_ent = Entry(self.control_fr, textvariable=self.world_size_var) self.world_size_ent.grid(row=1, column=1) #Control - Update self.update_btn = Button(self.control_fr, text="Update") self.update_btn.grid(row=2, column=0, columnspan=2) #Map Frame self.map_fr = Frame(self) self.map_fr.pack(side=LEFT, fill=BOTH, expand=1) #Map - Location Label self.loc_var = StringVar() self.loc_var.set("Location: ") self.loc_lbl = Label(self.map_fr, textvariable=self.loc_var) self.loc_lbl.pack() #Map - Canvas self.map_can = Canvas(self.map_fr, bg="gray") self.map_can.pack(fill=BOTH, expand=1) if ___name___ == "__main__": root = Root() root.mainloop()

  • @chaosmachines934
    @chaosmachines934 3 місяці тому

    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

    • @CodeQuest1
      @CodeQuest1 3 місяці тому

      Thank you for taking a look at the video! If you want to use your own weapon graphics you would change this part of the code: self.img = PhotoImage(file="Your Image File Path") Let me know if this answered your question or if you have any other questions!

  • @CodeQuest1
    @CodeQuest1 3 місяці тому

    FINAL CODE from tkinter import * import math 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(), Staff(), Bow(), ] self.cur_weapon = None #Canvas Dimensions can_w = self.winfo_reqwidth() can_h = self.winfo_reqheight() #Weapon Label self.weapon_var = StringVar() self.weapon_var.set("Weapon:") self.weapon_var.trace_add("write", self.trace) self.weapon_lbl = Label(self, textvariable=self.weapon_var) 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.tag_bind(weapon.tag + "_img", "<Enter>", lambda e: self.fill_item(e, "out_circle", weapon.fill_color)) self.tag_bind(weapon.tag + "_img", "<Button-1>", lambda e, weapon=weapon: self.update_weapon(e, weapon)) self.tag_bind(self.out_circle, "<Enter>", lambda e: self.fill_item(e, "out_circle", weapon.fill_color)) self.tag_bind(self.out_circle, "<Leave>", lambda e: self.fill_item(e, "out_circle", "")) self.tag_bind(self.out_circle, "<Button-1>", lambda e, weapon=weapon: self.update_weapon(e, weapon)) elif len(self.weapons) > 1: extent_add = 360 / len(self.weapons) for weapon in self.weapons: idx = self.weapons.index(weapon) #Create Arcs arc_x = can_w // 4 arc_y = can_h // 4 arc_x1 = can_w - arc_x arc_y1 = can_h - arc_y arc_start = 90 + (extent_add * idx) self.create_arc(arc_x, arc_y, arc_x1, arc_y1, start=arc_start, extent=extent_add, tags=weapon.tag, width=2) self.tag_bind(weapon.tag, "<Enter>", lambda e, weapon=weapon: self.fill_item(e, weapon.tag, weapon.fill_color)) self.tag_bind(weapon.tag, "<Leave>", lambda e, weapon=weapon: self.fill_item(e, weapon.tag, "")) self.tag_bind(weapon.tag, "<Button-1>", lambda e, weapon=weapon: self.update_weapon(e, weapon)) #Calc Weapon Img Coords #1. Calc Outer Circle Midpoint center_x = (out_circle_x + out_circle_x1) // 2 center_y = (out_circle_y + out_circle_y1) // 2 #2. Calc Midpoint Angle midpoint_angle = arc_start + (extent_add // 2) #3. Convert Midpoint Angle to Radians midpoint_radians = math.radians(midpoint_angle) #4. Calc Radii radius_x = (out_circle_x1 - out_circle_x) // 2 radius_y = (out_circle_y1 - out_circle_y) // 2 #5. Account for Image Size radius_x -= weapon.img.width() // 2 radius_y -= weapon.img.height() // 2 #6. Calc Arc Midpoint midpoint_x = center_x + radius_x * math.cos(midpoint_radians) midpoint_y = center_y - radius_y * math.sin(midpoint_radians) #7. Account for Image Size midpoint_x -= (weapon.img.width() // 2) * math.cos(midpoint_radians) midpoint_y += (weapon.img.height() // 2) * math.sin(midpoint_radians) #Display Image self.create_image(midpoint_x, midpoint_y, image=weapon.img, tags=weapon.tag + "_img") self.tag_bind(weapon.tag + "_img", "<Enter>", lambda e, weapon=weapon: self.fill_item(e, weapon.tag, weapon.fill_color)) self.tag_bind(weapon.tag + "_img", "<Leave>", lambda e, weapon=weapon: self.fill_item(e, weapon.tag, "")) self.tag_bind(weapon.tag + "_img", "<Button-1>", lambda e, weapon=weapon: self.update_weapon(e, weapon)) self.pack() def fill_item(self, e, tag, color): self.itemconfigure(tag, fill=color) self.update() def update_weapon(self, e, weapon): self.cur_weapon = weapon self.weapon_var.set("Weapon: " + weapon.name) self.itemconfigure(weapon.tag, fill=weapon.fill_color) def trace(self, *args): for weapon in self.weapons: if not self.cur_weapon == weapon: #Arc Binding self.tag_bind(weapon.tag, "<Leave>", lambda e, weapon=weapon: self.fill_item(e, weapon.tag, "")) self.fill_item(None, weapon.tag, "") else: #Arc Unbinding self.tag_unbind(weapon.tag, "<Leave>") 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" class Staff(Weapon): def __init__(self): super().__init__() self.name = "Staff" self.img = PhotoImage(file="Staff 50x50.png") self.fill_color = "blue" self.tag = "staff" class Bow(Weapon): def __init__(self): super().__init__() self.name = "Bow" self.img = PhotoImage(file="Bow 50x50.png") self.fill_color = "green" self.tag = "bow" if ___name___ == "__main__": root = Root() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 3 місяці тому

    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(), ] self.cur_weapon = None #Canvas Dimensions can_w = self.winfo_reqwidth() can_h = self.winfo_reqheight() #Weapon Label self.weapon_var = StringVar() self.weapon_var.set("Weapon:") self.weapon_lbl = Label(self, textvariable=self.weapon_var) 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.tag_bind(weapon.tag + "_img", "<Enter>", lambda e: self.fill_item(e, "out_circle", weapon.fill_color)) self.tag_bind(weapon.tag + "_img", "<Button-1>", lambda e, weapon=weapon: self.update_weapon(e, weapon)) self.tag_bind(self.out_circle, "<Enter>", lambda e: self.fill_item(e, "out_circle", weapon.fill_color)) self.tag_bind(self.out_circle, "<Leave>", lambda e: self.fill_item(e, "out_circle", "")) self.tag_bind(self.out_circle, "<Button-1>", lambda e, weapon=weapon: self.update_weapon(e, weapon)) self.pack() def fill_item(self, e, tag, color): self.itemconfigure(tag, fill=color) self.update() def update_weapon(self, e, weapon): self.cur_weapon = weapon self.weapon_var.set("Weapon: " + weapon.name) self.itemconfigure(weapon.tag, fill=weapon.fill_color) 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()

  • @CodeQuest1
    @CodeQuest1 3 місяці тому

    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_var.set("Weapon:") self.weapon_lbl = Label(self, textvariable=self.weapon_var) 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()

  • @CodeQuest1
    @CodeQuest1 4 місяці тому

    FINAL CODE: from tkinter import * root = Tk() root.state("zoomed") can = Canvas(root, width=500, height=500, bd=2, highlightbackground="black") can.pack() cur_health = 95 max_health = 100 def update_health_bar(): global can global cur_health global max_health arc_space = 20 can.delete("all") can_w = can.winfo_reqwidth() can_h = can.winfo_reqheight() #Outer Circle out_circle_x = can_w // 4 out_circle_y = can_h // 4 out_circle_x1 = can_w - (can_w // 4) out_circle_y1 = can_h - (can_h // 4) #Inner Circle in_circle_x = out_circle_x - arc_space in_circle_y = out_circle_y - arc_space in_circle_x1 = out_circle_x1 + arc_space in_circle_y1 = out_circle_y1 + arc_space #Arc arc_x = (out_circle_x + in_circle_x) // 2 arc_y = (out_circle_y + in_circle_y) // 2 arc_x1 = (out_circle_x1 + in_circle_x1) // 2 arc_y1 = (out_circle_y1 + in_circle_y1) // 2 arc_extent = 360 * (cur_health / max_health) if arc_extent < 360: can.create_arc(arc_x, arc_y, arc_x1, arc_y1, style="arc", extent=arc_extent, width=arc_space, outline="red", start=90) else: can.create_oval(arc_x, arc_y, arc_x1, arc_y1, width=arc_space, outline="red") #Draw Outer & Inner Circle can.create_oval(out_circle_x, out_circle_y, out_circle_x1, out_circle_y1, width=2) can.create_oval(in_circle_x, in_circle_y, in_circle_x1, in_circle_y1, width=2) #Text can.create_text(can_w // 2, can_h // 2, text=str(cur_health) + "%") update_health_bar() root.mainloop()

  • @CodeQuest1
    @CodeQuest1 5 місяців тому

    I misspoke at 4:40, what I meant to say was that "If you change the current health to anything below 100 and run the code, the health bar should reflect that change."

  • @RidahShoorbajee
    @RidahShoorbajee 5 місяців тому

    nice

  • @kittykittykittywhere
    @kittykittykittywhere Рік тому

    Thank you, adding a personal touch to games is a really nice upgrade to never be without.

    • @CodeQuest1
      @CodeQuest1 Рік тому

      Yes, I agree! P.S. I've never thanked you for being my first subscriber. Your subscription really motivated me to make more tutorials, so thank you!

    • @kittykittykittywhere
      @kittykittykittywhere Рік тому

      @@CodeQuest1 I'm so glad I did, then!

  • @tomcole2608
    @tomcole2608 Рік тому

    "Promo SM" 😊

  • @CodeQuest1
    @CodeQuest1 2 роки тому

    I was completely wrong about how the show menu function worked vs. how the ShowMenu worked so I just posted links to both of their documentation in the video description.