Skip to content

Commit a9416a8

Browse files
committed
fix bugs
Update code with support python 3.13.5
1 parent 4475318 commit a9416a8

File tree

32 files changed

+2479
-1795
lines changed

32 files changed

+2479
-1795
lines changed

Downloaded Files Organizer/move_to_directory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import shutil
33

4+
45
ext = {
56
"web": "css less scss wasm ",
67
"audio": "aac aiff ape au flac gsm it m3u m4a mid mod mp3 mpa pls ra s3m sid wav wma xm ",

Droplistmenu/GamesCalender.py

Lines changed: 171 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,172 @@
1-
2-
from tkinter import *
3-
from tkcalendar import Calendar
41
import tkinter as tk
5-
6-
7-
window = tk.Tk()
8-
9-
# Adjust size
10-
window.geometry("600x500")
11-
12-
gameList =["Game List:"]
13-
# Change the label text
14-
def show():
15-
game = selected1.get() + " vs " + selected2.get()+" on "+cal.get_date()
16-
gameList.append(game)
17-
#print(gameList)
18-
gameListshow = "\n".join(gameList)
19-
#print(gameList)
20-
label.config(text=gameListshow)
21-
22-
23-
# Dropdown menu options
24-
options = [
25-
"Team 1",
26-
"Team 2",
27-
"Team 3",
28-
"Team 4",
29-
"Team 5",
30-
"Team 6"
31-
]
32-
33-
# datatype of menu text
34-
selected1 = StringVar()
35-
selected2 = StringVar()
36-
37-
# initial menu text
38-
selected1.set("Team 1")
39-
selected2.set("Team 2")
40-
41-
# Create Dropdown menu
42-
L1 = Label(window, text="Visitor")
43-
L1.place(x=40, y=35)
44-
drop1 = OptionMenu(window, selected1, *options)
45-
drop1.place(x=100, y=30)
46-
47-
L2 = Label(window, text="VS")
48-
L2.place(x=100, y=80)
49-
50-
L3 = Label(window, text="Home")
51-
L3.place(x=40, y=115)
52-
drop2 = OptionMenu(window, selected2, *options)
53-
drop2.place(x=100, y=110)
54-
55-
# Add Calendar
56-
cal = Calendar(window, selectmode='day',
57-
year=2022, month=12,
58-
day=1)
59-
60-
cal.place(x=300, y=20)
61-
62-
63-
64-
# Create button, it will change label text
65-
button = Button( window, text="Add to calender", command=show).place(x=100,y=200)
66-
67-
# Create Label
68-
label = Label(window, text=" ")
69-
label.place(x=150, y=250)
70-
71-
window.mainloop()
2+
from tkinter import StringVar, Label, Button, OptionMenu
3+
from tkcalendar import Calendar # Install via: pip install tkcalendar
4+
5+
def main() -> None:
6+
"""Create and run the sports schedule management application"""
7+
# Create main application window
8+
window = tk.Tk()
9+
window.title("Sports Schedule Manager")
10+
window.geometry("600x500")
11+
window.resizable(True, True) # Allow window resizing
12+
13+
# Initialize list to store scheduled games
14+
game_list: list[str] = ["Game List:"]
15+
16+
# Available teams for dropdown selection
17+
team_options: list[str] = [
18+
"Team 1", "Team 2", "Team 3",
19+
"Team 4", "Team 5", "Team 6"
20+
]
21+
22+
# Create and arrange all GUI components
23+
create_widgets(window, game_list, team_options)
24+
25+
# Start the main event loop
26+
window.mainloop()
27+
28+
def create_widgets(
29+
window: tk.Tk,
30+
game_list: list[str],
31+
team_options: list[str]
32+
) -> None:
33+
"""Create and position all GUI widgets in the main window"""
34+
# Variables to store selected teams
35+
visitor_var: StringVar = StringVar(window)
36+
home_var: StringVar = StringVar(window)
37+
38+
# Set default selections
39+
visitor_var.set(team_options[0])
40+
home_var.set(team_options[1])
41+
42+
# Configure grid weights for responsive layout
43+
window.columnconfigure(0, weight=1)
44+
window.columnconfigure(1, weight=1)
45+
window.rowconfigure(0, weight=1)
46+
window.rowconfigure(1, weight=1)
47+
window.rowconfigure(2, weight=3)
48+
49+
# Create left frame for team selection
50+
left_frame = tk.Frame(window, padx=10, pady=10)
51+
left_frame.grid(row=0, column=0, rowspan=2, sticky="nsew")
52+
53+
# Visitor team selection
54+
visitor_label = Label(left_frame, text="Visitor:")
55+
visitor_label.grid(row=0, column=0, sticky="w", pady=5)
56+
57+
visitor_dropdown = OptionMenu(left_frame, visitor_var, *team_options)
58+
visitor_dropdown.grid(row=0, column=1, sticky="ew", pady=5)
59+
60+
# Home team selection
61+
home_label = Label(left_frame, text="Home:")
62+
home_label.grid(row=1, column=0, sticky="w", pady=5)
63+
64+
home_dropdown = OptionMenu(left_frame, home_var, *team_options)
65+
home_dropdown.grid(row=1, column=1, sticky="ew", pady=5)
66+
67+
# Create calendar frame on the right
68+
right_frame = tk.Frame(window, padx=10, pady=10)
69+
right_frame.grid(row=0, column=1, rowspan=2, sticky="nsew")
70+
71+
calendar = Calendar(
72+
right_frame,
73+
selectmode='day',
74+
year=2023,
75+
month=7,
76+
day=16
77+
)
78+
calendar.pack(fill="both", expand=True)
79+
80+
# Create game list display area
81+
display_frame = tk.Frame(window, padx=10, pady=10)
82+
display_frame.grid(row=2, column=0, columnspan=2, sticky="nsew")
83+
84+
# Text widget with scrollbar for game list
85+
game_display = tk.Text(display_frame, wrap=tk.WORD, height=10)
86+
game_display.pack(side=tk.LEFT, fill="both", expand=True)
87+
88+
scrollbar = tk.Scrollbar(display_frame, command=game_display.yview)
89+
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
90+
game_display.config(yscrollcommand=scrollbar.set)
91+
92+
# Initialize display with empty list
93+
update_game_display(game_display, game_list)
94+
95+
# Add to schedule button - pass game_display to add_game
96+
add_button = Button(
97+
left_frame,
98+
text="Add to Schedule",
99+
command=lambda: add_game(
100+
window, game_list, visitor_var, home_var, calendar, game_display
101+
)
102+
)
103+
add_button.grid(row=2, column=0, columnspan=2, pady=20)
104+
105+
# Configure weights for responsive resizing
106+
left_frame.columnconfigure(1, weight=1)
107+
right_frame.columnconfigure(0, weight=1)
108+
right_frame.rowconfigure(0, weight=1)
109+
display_frame.columnconfigure(0, weight=1)
110+
display_frame.rowconfigure(0, weight=1)
111+
112+
def add_game(
113+
window: tk.Tk,
114+
game_list: list[str],
115+
visitor_var: StringVar,
116+
home_var: StringVar,
117+
calendar: Calendar,
118+
game_display: tk.Text # Added game_display parameter
119+
) -> None:
120+
"""Add a new game to the schedule and update the display"""
121+
# Get selected values
122+
visitor = visitor_var.get()
123+
home = home_var.get()
124+
date = calendar.get_date()
125+
126+
# Validate input (prevent same team match)
127+
if visitor == home:
128+
show_error(window, "Error", "Visitor and home teams cannot be the same!")
129+
return
130+
131+
# Create game entry and add to list
132+
game_entry = f"{visitor} vs {home} on {date}"
133+
game_list.append(game_entry)
134+
135+
# Update the display with new list
136+
update_game_display(game_display, game_list)
137+
138+
def update_game_display(display: tk.Text, game_list: list[str]) -> None:
139+
"""Update the text widget with current game list"""
140+
# Clear existing content
141+
display.delete(1.0, tk.END)
142+
# Insert updated list
143+
display.insert(tk.END, "\n".join(game_list))
144+
145+
def show_error(window: tk.Tk, title: str, message: str) -> None:
146+
"""Display an error message in a modal dialog"""
147+
error_window = tk.Toplevel(window)
148+
error_window.title(title)
149+
error_window.geometry("300x150")
150+
error_window.resizable(False, False)
151+
152+
# Center error window over main window
153+
error_window.geometry("+%d+%d" % (
154+
window.winfo_rootx() + window.winfo_width() // 2 - 150,
155+
window.winfo_rooty() + window.winfo_height() // 2 - 75
156+
))
157+
158+
# Error message label
159+
message_label = Label(error_window, text=message, padx=20, pady=20)
160+
message_label.pack(fill="both", expand=True)
161+
162+
# Close button
163+
close_button = Button(error_window, text="OK", command=error_window.destroy)
164+
close_button.pack(pady=10)
165+
166+
# Make dialog modal
167+
error_window.transient(window)
168+
error_window.grab_set()
169+
window.wait_window(error_window)
170+
171+
if __name__ == "__main__":
172+
main()

Electronics_Algorithms/resistance.py

Lines changed: 59 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,65 @@
1-
def resistance_calculator(material:str, lenght:float, section:float, temperature:float):
2-
"""
3-
material is a string indicating the material of the wire
4-
5-
lenght is a floating value indicating the lenght of the wire in meters
1+
def resistance_calculator(
2+
material: str,
3+
length: float,
4+
section: float,
5+
temperature: float
6+
) -> str:
7+
"""
8+
Calculate the electrical resistance of a wire based on its properties.
69
7-
diameter is a floating value indicating the diameter of the wire in millimeters
10+
Parameters:
11+
material (str): Material of the wire (available: silver, copper, aluminium, tungsten, iron, steel, zinc, solder)
12+
length (float): Length of the wire in meters
13+
section (float): Cross-sectional area of the wire in square millimeters (mm²)
14+
temperature (float): Operating temperature of the wire in °C
815
9-
temperature is a floating value indicating the temperature at which the wire is operating in °C
16+
Returns:
17+
str: Calculated resistance in ohms (Ω)
18+
"""
19+
# Material properties: resistivity at 20°C (ρ in Ω·mm²/m) and temperature coefficient (α in 1/°C)
20+
materials: dict[str, dict[str, float]] = {
21+
"silver": {
22+
"rho": 0.0163,
23+
"coefficient": 0.0038
24+
},
25+
"copper": {
26+
"rho": 0.0178,
27+
"coefficient": 0.00381
28+
},
29+
"aluminium": {
30+
"rho": 0.0284,
31+
"coefficient": 0.004
32+
},
33+
"tungsten": {
34+
"rho": 0.055,
35+
"coefficient": 0.0045
36+
},
37+
"iron": {
38+
"rho": 0.098,
39+
"coefficient": 0.006
40+
},
41+
"steel": {
42+
"rho": 0.15,
43+
"coefficient": 0.0047
44+
},
45+
"zinc": {
46+
"rho": 0.06,
47+
"coefficient": 0.0037
48+
},
49+
"solder": {
50+
"rho": 0.12,
51+
"coefficient": 0.0043
52+
}
53+
}
1054

11-
Available materials:
12-
- silver
13-
- copper
14-
- aluminium
15-
- tungsten
16-
- iron
17-
- steel
18-
- zinc
19-
- solder"""
55+
# Get material properties (will raise KeyError for invalid materials)
56+
rho_20deg: float = materials[material]["rho"]
57+
temp_coefficient: float = materials[material]["coefficient"]
2058

21-
materials = {
22-
"silver": {
23-
"rho": 0.0163,
24-
"coefficient": 0.0038
25-
},
59+
# Calculate resistivity at operating temperature
60+
rho: float = rho_20deg * (1 + temp_coefficient * (temperature - 20))
2661

27-
"copper": {
28-
"rho": 0.0178,
29-
"coefficient": 0.00381
30-
},
62+
# Calculate resistance (R = ρ * L / S)
63+
resistance: float = rho * length / section
3164

32-
"aluminium": {
33-
"rho": 0.0284,
34-
"coefficient": 0.004
35-
},
36-
37-
"tungsten": {
38-
"rho": 0.055,
39-
"coefficient": 0.0045
40-
},
41-
42-
"iron": {
43-
"rho": 0.098,
44-
"coefficient": 0.006
45-
},
46-
47-
"steel": {
48-
"rho": 0.15,
49-
"coefficient": 0.0047
50-
},
51-
52-
"zinc": {
53-
"rho": 0.06,
54-
"coefficient": 0.0037
55-
},
56-
57-
"solder": {
58-
"rho": 0.12,
59-
"coefficient": 0.0043
60-
}
61-
}
62-
63-
rho_20deg = materials[material]["rho"]
64-
temp_coefficient = materials[material]["coefficient"]
65-
66-
rho = rho_20deg * (1 + temp_coefficient * (temperature - 20))
67-
resistance = rho * lenght / section
68-
69-
return f"{resistance}Ω"
65+
return f"{resistance}Ω"

Emoji Dictionary/QT_GUI.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11

2-
# -*- coding: utf-8 -*-
3-
42
import sys
53
from PyQt5.QtCore import *
64
from PyQt5.QtGui import *

0 commit comments

Comments
 (0)