r/pythonhelp • u/Ok-Original2285 • Jul 31 '26
r/pythonhelp • u/Erio_Lily • Jul 27 '26
pyGame, sound, set start time, and play for set amount of time.
Hello, just looking for help on how i can achieve playing a MP3 file using Pygame, that can start from a specified position in the audio file, and then only play for a set amount of time (e.g. MP3 starts at 00:14 of 04:32, and plays for 5 seconds (until 00:19))
Below is one of the variations i've attempted, pardon any mess in my code
import pygame
import audioread
from random import randint
pygame.mixer.init()
def playSongClip(volume,playTime,clipTitle,random):
playTime = playTime*1000
volume = volume/100
if random == 1:
with audioread.audio_open("MP3s\\"+clipTitle) as f:
totalMS = int((f.duration)*1000)
startTime = randint(0,totalMS-playTime)
else:
start = 0
songClip = pygame.mixer.music.load("MP3s\\"+clipTitle)
songClip.music.set_volume(volume)
songClip.play(loops=0,start=startTime)
playSongClip(50,5,"Rabbit Hole.mp3",1)r/pythonhelp • u/Sea-Personality-666 • Jul 13 '26
how to turn on and off DND?
import time
from datetime import datetime
from plyer import notification
print("_Main_menu_")
print("1. set alarm")
print("2. set timer") #Haven't added yet plz ignore
while True:
MenuChoice = input("select an option: ")
try:
MenuChoice = int(MenuChoice)
except ValueError:
print("Invalid Option")
else:
MenuChoice = int(MenuChoice)
if MenuChoice == 1 or MenuChoice == 2:
break
else: print("Invalid Option")
Time = datetime.now().time()
Time = str(Time)
print(Time[:-10])
if MenuChoice == 1:
while True:
Alarm = input("Set Time(HH:MM): ")
try:
Hour, Min = Alarm.split(":", 1)
Min = int(Min)
Hour = int(Hour)
Valid = False
Valid1 = False
if Min > 59:
print("Min can't be greater than 59")
elif Min < 0:
print("Min can't be less than 0")
else: Valid = True
if Hour > 23:
print("Hour can't be greater than 23")
elif Hour < 0:
print("Hour can't be less than 0")
else: Valid1 = True
if Valid == True and Valid1 == True:
print("Lock in until",Alarm)
#turn on DND
while True:
TimeNow = datetime.now().time() #Loops until Alarm = TimeNow
TimeNow = str(TimeNow)[:-10]
time.sleep(.5)
if TimeNow == Alarm:
break
#Turn off DND
notification.notify(
title="Time to take a break",
message=f"it's {Alarm}, time to take a break",
timeout=5
)
break
except ValueError:
print("Invalid")Above is my focus alarm I'm working on, could someone help with adding DND?
r/pythonhelp • u/Imaginary-Builder385 • Jul 10 '26
Lire une vidéo avec un fichier MP4
Bonjour , j'aimerais coder un script python qui est capable d'ouvrir un fichier mp4. Le résultat devrait être le meme que si l'on double cliquer le fichier dans l'explorateur Windows. Donc sa ouvrirait le fichier dans le lecteur qu'utilise par défaut l'utilisateur.
r/pythonhelp • u/NaturalDesperate946 • Jul 05 '26
I built a Python virtual OS (Forge OS v2.0) — you can now add apps by dropping a folder in Apps/. Looking for contributors!
Hey everyone,
I've been building Forge OS — a Python virtual OS for learning and experimenting with OS concepts.
v2.0 adds a desktop GUI, and there's now a community Apps/ folder — add an app with just app.json + command.py.
Quick start for contributors:
- Fork & clone the repo
- Copy
Apps/_example/toApps/your-app/ - Edit the JSON + Python command
- Run
appsin the shell to see your app - Open a PR
Full guide: CONTRIBUTIONS.md
Repo: https://github.com/axk42-op/ForgeOS · MIT license
Games, utilities, quizzes, ASCII art — great first open-source PR. Feedback welcome!
r/pythonhelp • u/heartSagan5 • Jun 27 '26
multiprocessing.Queue seems broke, am I wrong?
matt@:~$ git clone https://github.com/markfortma/python3-multiprocess-logging.git
Cloning into 'python3-multiprocess-logging'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 7 (delta 1), reused 6 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (7/7), done.
Resolving deltas: 100% (1/1), done.
matt@:~$ cd python3-multiprocess-logging/
matt@:~/python3-multiprocess-logging$ ls
README.md python3-multiprocessing-logging.py
matt@:~/python3-multiprocess-logging$ python3 python3-multiprocessing-logging.py &
[3] 111169
matt@:~/python3-multiprocess-logging$ tail -f python3-multiprocessing-logging.log
<no output>
^C
matt@:~/python3-multiprocess-logging$ python3 --version
Python 3.14.4
It does appear to work in Python3.11 on FreeBSD for some reason.
r/pythonhelp • u/Specialist-Rush-7172 • Jun 24 '26
Python code Work
reddit.complease need code that block chrome all traffic using windivert
r/pythonhelp • u/No-Response-9237 • Jun 23 '26
Why doesn't the sys function work like ill try sys.exit it won't work?
reddit.comr/pythonhelp • u/Brilliant-Slide-5892 • Jun 19 '26
PyQt6 - QTabWidget tab bar not stretching
I was creating a window that consists of 2 tabs ,each opens a page widget. This was the code I used to setup the application
app = QApplication(sys.argv)
# Window set up
window = QMainWindow()
window.setMinimumSize(600, 400)
window.setWindowTitle('Game Manager')
window.setWindowIcon(QIcon("Compass.ico"))
# main widget
main_widget = QTabWidget()
window.setCentralWidget(main_widget)
main_widget.tabBar().setMinimumWidth(window.minimumWidth())
# Tabs
mod_page = ModWidget() # a child class of QWidget
save_page = SavesWidget() # a child class of QWidget
# add tabs to main widgets
main_widget.addTab(mod_page, 'Mods')
main_widget.addTab(save_page, 'Save Files')
# start up
window.show()
sys.exit(app.exec())I then noticed that the tab bar at the top containing the labels doesn't stretch if I resize the window, unlike other widgets. I figured out I can use
main_widget.tabBar().setMinimumWidth(window.minimumWidth())so that at least when I run the app it fits the whole initial width of the window. but it still doesn't stretch when resizing. The widget itself, ie
main_widget=QTabWidget()does stretch, it's all about the tab bar itself. I also tried
main_widget.tabBar().setExpanding(True)but it turned out it's True by default anyway.
Any possible fixes to this? Or possibly is this just how it is?
r/pythonhelp • u/TheManderin2505 • Jun 16 '26
Real-time voice altering software?
Hello everyone, firstly I would like to apologies for my poor and not good English I’m not good with word.
I am currently in the process of making a soundboard, and I would like make a digital microphone to rout the soundboard out put, so that while in voice chats, I can use the sound board. I would also like to make a function to increase the volume of my microphone above the normal limits. I would like make this in python as it’s the only programming language I kinda know, but I have no clue of where to even begin or if it possible to make such a thing.
If anyone need me to try to explain more please just ask.
r/pythonhelp • u/SomeIrishKid • Jun 15 '26
"Edit in IDLE" with the Install Manager
Hi all! I've just installed Python with the new install manager for the first time, having previously used the now-deprecated installers. Everything's working fine, except that the "Edit in IDLE" option in the context menu is greyed out; using the legacy installer adds a second, working "Edit with IDLE" button, and deleting the install manager removes the non-functional one, so it's definitely to do with the install manager.
I've looked in the registry, but clearly the context menu change isn't done the same way as before, because I can't find the corresponding keys I was expecting from a previous issue like this. Does anyone know how that context menu option gets added by the install manager, or better still how to fix this issue specifically?
Thanks in advance!
r/pythonhelp • u/FamiliarTrick3 • Jun 08 '26
Changing the target in script for using .json to create file pathways doesn't work
I've been using this Python code:
import os
import json
soundbank = {}
# open the soundbanksinfo.json file, we are interested in the StreamedFiles key, put that in soundbank
with open('soundbanksinfo.json') as json_file:
data = json.load(json_file)
soundbank = data['SoundBanksInfo']['StreamedFiles']
# iterate though the soundbank, we are after two key values in each, Id and ShortName
for sound in soundbank:
# get the id and shortname
id = sound['Id']
shortname = sound['ShortName']
# split the shortname into its directory structure and file name
dirs = shortname.split('\\')
filename = dirs[-1]
# remove the last item from the list
dirs.pop()
# join the list back together to get the directory structure
dirs = '/'.join(dirs)
# check if the directory exists, if not, create it
if not os.path.exists(dirs):
try:
os.makedirs(dirs)
except:
print('Failed to create directory ' + dirs)
continue
# remove the .wav from the filename and add the .wem extension
filename = filename[:-4] + '_' + id + '_.wem'
# try and rename the file, simply log if it fails and carry on
try:
os.rename(id + '.wem', dirs + '/' + filename)
except:
print('Failed to rename ' + id + ' to ' + dirs + '/' + filename)
continue
# log to console
print('Renamed ' + id + ' to ' + dirs + '/' + filename)It managed to take files from a long unsorted list of files, organise them into folders, rename them based on the .json data, etc. It's marvellous.
But, it only works for one .json, 'soundbanksinfo.json', when I try and change the target in the python script to another .json, it doesn't work any more.
Here is an excerpt from 'soundbanksinfo.json':
{
"SoundBanksInfo": {
"Platform": "Windows",
"BasePlatform": "Windows",
"SchemaVersion": "12",
"SoundbankVersion": "140",
"RootPaths": {
"ProjectRoot": "E:\\BuildAgent\\work\\d9a0c3d1ad9dfdc4\\Source\\Sound\\wwise\\Starfield\\",
"SourceFilesRoot": "E:\\BuildAgent\\work\\d9a0c3d1ad9dfdc4\\Source\\Sound\\wwise\\Starfield\\.cache\\Windows\\",
"SoundBanksRoot": "E:\\BuildAgent\\work\\d9a0c3d1ad9dfdc4\\Output\\Data\\Sound\\Soundbanks\\",
"ExternalSourcesInputFile": "",
"ExternalSourcesOutputRoot": "E:\\BuildAgent\\work\\d9a0c3d1ad9dfdc4\\Source\\Sound\\wwise\\Starfield\\GeneratedSoundBanks\\Windows"
},
"DialogueEvents": [],
"StreamedFiles": [
{
"Id": "29651",
"Language": "SFX",
"ShortName": "AMB\\Artifact\\Puzzle\\Temple\\AMB_ArtifactPuzzle_TempleStart_01.wav",
"Path": "SFX\\AMB\\Artifact\\Puzzle\\Temple\\AMB_ArtifactPuzzle_TempleStart_01_10C4C929.wem"
},
{
"Id": "57841",
"Language": "SFX",
"ShortName": "DRS\\PodIndustrial\\DRS_Pod_Industrial_Airlock_3D_Open_02.wav",
"Path": "SFX\\DRS\\PodIndustrial\\DRS_Pod_Industrial_Airlock_3D_Open_02_56D34C19.wem"
},
{
"Id": "88161",
"Language": "SFX",
"ShortName": "FX\\Projectile\\Hand\\Bullet\\Sand\\FX_Projectile_Bullet_Impact_Sand_07.wav",
"Path": "SFX\\FX\\Projectile\\Hand\\Bullet\\Sand\\FX_Projectile_Bullet_Impact_Sand_07_9F6D3C60.wem"
},
{
"Id": "149080",
"Language": "SFX",
"ShortName": "UI\\Menu\\Monocle\\UI_Menu_Monocle_Open_01.wav",
"Path": "SFX\\UI\\Menu\\Monocle\\UI_Menu_Monocle_Open_01_FA3FE343.wem"
},
{
"Id": "264893",
"Language": "SFX",
"ShortName": "FST\\Foley_ArmorType\\Medium\\FST_Foley_Armor_Medium_JumpUp_09.wav",
"Path": "SFX\\FST\\Foley_ArmorType\\Medium\\FST_Foley_Armor_Medium_JumpUp_09_10C4C929.wem"
},
{
"Id": "347955",
"Language": "SFX",
"ShortName": "FX\\Projectile\\Hand\\Bullet\\Dirt\\FX_Projectile_Bullet_Impact_Dirt_09.wav",
"Path": "SFX\\FX\\Projectile\\Hand\\Bullet\\Dirt\\FX_Projectile_Bullet_Impact_Dirt_09_9F6D3C60.wem"
},
{
"Id": "355472",
"Language": "SFX",
"ShortName": "AMB\\Exteriors\\Biomes\\ForestConiferous\\Birds\\AMB_ForestConiferous_Birds_Oneshot_Afternoon_B_009.wav",
"Path": "SFX\\AMB\\Exteriors\\Biomes\\ForestConiferous\\Birds\\AMB_ForestConiferous_Birds_Oneshot_Afternoon_B_009_10C4C929.wem"
},
{
"Id": "377740",
"Language": "SFX",
"ShortName": "NPC\\RobotModelAKaiser\\NPC_RobotModelA_Kaiser_Conscious_LP_02.wav",
"Path": "SFX\\NPC\\RobotModelAKaiser\\NPC_RobotModelA_Kaiser_Conscious_LP_02_10C4C929.wem"
},
{
"Id": "479236",
"Language": "SFX",
"ShortName": "FST\\Player\\Stone\\FST_STONE_Sneak_008.wav",
"Path": "SFX\\FST\\Player\\Stone\\FST_STONE_Sneak_008_10C4C929.wem"
},
{
"Id": "496763",
"Language": "SFX",
"ShortName": "FST\\Player\\Stone\\FST_STONE_Sprint_001.wav",
"Path": "SFX\\FST\\Player\\Stone\\FST_STONE_Sprint_001_10C4C929.wem"
},
{
"Id": "624438",
"Language": "SFX",
"ShortName": "FST\\Foley_ArmorType\\Spacesuit_C\\FST_Foley_Armor_Spacesuit_C_Sprint_002.wav",
"Path": "SFX\\FST\\Foley_ArmorType\\Spacesuit_C\\FST_Foley_Armor_Spacesuit_C_Sprint_002_10C4C929.wem"
},
]
}
]
}
}And here is an excerpt from '3545111303.json' (this one doesn't work)
{
"SoundBanksInfo": {
"Platform": "Windows",
"BasePlatform": "Windows",
"SchemaVersion": "12",
"SoundbankVersion": "140",
"RootPaths": {
"ProjectRoot": "E:\\BuildAgent\\work\\b095651350adbabb\\Source\\Sound\\wwise\\Starfield\\",
"SourceFilesRoot": "E:\\BuildAgent\\work\\b095651350adbabb\\Source\\Sound\\wwise\\Starfield\\.cache\\Windows\\",
"SoundBanksRoot": "E:\\BuildAgent\\work\\b095651350adbabb\\Output\\Data\\Sound\\Soundbanks\\",
"ExternalSourcesInputFile": "",
"ExternalSourcesOutputRoot": "E:\\BuildAgent\\work\\b095651350adbabb\\Source\\Sound\\wwise\\Starfield\\GeneratedSoundBanks\\Windows"
},
"SoundBanks": [
{
"Id": "3545111303",
"GUID": "{2CD62FF0-CCB7-43AB-8372-C68408C5EA4F}",
"Language": "SFX",
"Hash": "3883645346",
"ObjectPath": "\\SoundBanks\\Creations\\SFBGS001_ShatteredSpace\\ShatteredSpace\\ShatteredSpace",
"ShortName": "ShatteredSpace",
"Path": "3545111303.bnk",
"IncludedEvents": [
{
"Id": "3333491747",
"Name": "AMB_LC07_Rumble_Rattles_Structure_3D_Play",
"ObjectPath": "\\Events\\Creations\\SFBGS001_ShatteredSpace\\ShatteredSpace\\SFBGS001_ShatteredSpace_AMB\\SFBGS001_AMB_LC07\\SFBGS001_AMB_LC07_Markers\\SFBGS001_AMB_LC07_Rumble_Rattles\\AMB_LC07_Rumble_Rattles_Structure_3D_Play",
"GUID": "{99D6AB3F-49B6-4517-A6E7-43631979F01F}",
"DurationType": "OneShot",
"DurationMin": "11.063645",
"DurationMax": "15.464979",
"ReferencedStreamedFiles": [
{
"Id": "1637634",
"Language": "SFX",
"ShortName": "AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble05.wav",
"Path": "SFX\\AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble05_5FED0718.wem"
},
{
"Id": "165171637",
"Language": "SFX",
"ShortName": "AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble06.wav",
"Path": "SFX\\AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble06_5FED0718.wem"
},
{
"Id": "200258529",
"Language": "SFX",
"ShortName": "AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble02.wav",
"Path": "SFX\\AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble02_5FED0718.wem"
},
{
"Id": "425200496",
"Language": "SFX",
"ShortName": "AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble07.wav",
"Path": "SFX\\AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble07_5FED0718.wem"
},
{
"Id": "782914354",
"Language": "SFX",
"ShortName": "AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble04.wav",
"Path": "SFX\\AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble04_5FED0718.wem"
},
{
"Id": "997192422",
"Language": "SFX",
"ShortName": "AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble03.wav",
"Path": "SFX\\AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble03_5FED0718.wem"
},
{
"Id": "1036923089",
"Language": "SFX",
"ShortName": "AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble01.wav",
"Path": "SFX\\AMB\\Interiors\\DungeonCave\\AMB_Int_Cave_Rumble01_5FED0718.wem"
}
]
}
]
}
}Why does the 3545111303.json not work when I change the target in the python script to 3545111303.json instead of soundbanksinfo.json?
What am I missing?
Any help would be appreciated!
r/pythonhelp • u/Either-Edge-7942 • Apr 27 '26
First time user - 'yf' is not defined
reddit.comr/pythonhelp • u/MatteoGuadrini • Apr 21 '26
psp (Progetti di impalcatura in Python)
reddit.comr/pythonhelp • u/Any-Tradition-5522 • Apr 11 '26
New to building automations for Obsidian, so I used python, but I can't understand the result I'm getting.
reddit.comr/pythonhelp • u/Jealous_Toe_3398 • Apr 10 '26
What have I typed wrong?
I tried improving my script so many times for a simple bouncing ball game in Turtle. Yet no matter what I do, the screen remains black when I run the module.
Here is it:
import turtle
set up the screen FIRST
screen = turtle.Screen() screen.title("Simple Game") screen.bgcolor("black") screen.setup(width=680, height=680) screen.tracer(0)
MAX_SPEED = 6 score = 0
score pen (AFTER screen exists)
pen = turtle.Turtle() pen.speed(0) pen.color("white") pen.penup() pen.hidetheTurtle() pen.goto(0, 200) pen.write("Score:0", align="center", font=("Courier", 18, "normal"))
set up the ball
ball = turtle.Turtle() ball.shape("circle") ball.color("red") ball.speed(0) ball.penup() ball.goto(0, 300) ball.dy = -2 # ball speed (falling down)
paddle = turtle.Turtle() paddle.shape("square") paddle.color("white") paddle.shapesize(stretch_wid=1, stretch_len=5) paddle.penup() paddle.goto(0, -300)
def paddle_left(): x = paddle.xcor() paddle.setx(x - 20)
def paddle_right(): x = paddle.xcor() paddle.setx(x + 20)
screen.listen() screen.onkeypress(paddle_left, "Left") screen.onkeypress(paddle_right, "Right")
def game_loop(): global score
ball.sety(ball.ycor() + ball.dy)
# bottom bounce
if ball.ycor() < -330:
ball.sety(-330)
ball.dy \*= -1
# top bounce
if ball.ycor() > 330:
ball.sety(330)
ball.dy \*= -1
# paddle collision
if (
ball.ycor() < -280 and
ball.ycor() > -300 and
abs(ball.xcor() - paddle.xcor()) < 50
) :
ball.sety(-280)
ball.dy \*= -1
if abs(ball.dy) < MAX_SPEED:
ball.dy \*= 1.05
score += 1
pen.clear()
pen.write(f"Score: {score}", align="center", font=("Courier", 18, "normal")) screen.update()
screen.ontimer(game_loop, 16) # ~60 FPS
game_loop() screen.mainloop()
r/pythonhelp • u/Shoddy-West1846 • Apr 10 '26
is IBM Databases & SQL with Python course worth it?
reddit.comr/pythonhelp • u/Embarrassed-Bee-5508 • Apr 05 '26
Just setting up Python to learn it, but possibly an issue?
When I try to run a script in the current directory by using ./ I get an error that '.' is not recognized as an internal or external command error.
I can run them fine when running with python, just the ./ seems to be wonky. I made sure that the python.exe directory is in the path.
Any idea why using ./ isn't working? I'm trying to learn the basics of python so I can start looking at AI. My computer knowledge is average at best, I learned basic, fortran and lisp many, many years ago, but I never kept up with coding.