Excuse the noob – cutting float input result to 1 decimal place /u/KazzJen Python Education

Excuse the noob – cutting float input result to 1 decimal place /u/KazzJen Python Education

Hi, I’m a total beginner so excuse my ignorance.

I wrote a program to convert Celsius to Farenheit. It works well for most temperature inputs except eg ’21’ where it returns a value to 14 decimal places where ideally I’d like it to be just one.

How do I format the output, please?

celsius = input(“What is the temperature in Celsius: “)

farenheit = float(celsius)*1.8+32

print(f”The temperature in Farenheit is: {farenheit}”)

Thanks in advance.

submitted by /u/KazzJen
[link] [comments]

​r/learnpython Hi, I’m a total beginner so excuse my ignorance. I wrote a program to convert Celsius to Farenheit. It works well for most temperature inputs except eg ’21’ where it returns a value to 14 decimal places where ideally I’d like it to be just one. How do I format the output, please? celsius = input(“What is the temperature in Celsius: “) farenheit = float(celsius)*1.8+32 print(f”The temperature in Farenheit is: {farenheit}”) Thanks in advance. submitted by /u/KazzJen [link] [comments] 

Hi, I’m a total beginner so excuse my ignorance.

I wrote a program to convert Celsius to Farenheit. It works well for most temperature inputs except eg ’21’ where it returns a value to 14 decimal places where ideally I’d like it to be just one.

How do I format the output, please?

celsius = input(“What is the temperature in Celsius: “)

farenheit = float(celsius)*1.8+32

print(f”The temperature in Farenheit is: {farenheit}”)

Thanks in advance.

submitted by /u/KazzJen
[link] [comments]  Hi, I’m a total beginner so excuse my ignorance. I wrote a program to convert Celsius to Farenheit. It works well for most temperature inputs except eg ’21’ where it returns a value to 14 decimal places where ideally I’d like it to be just one. How do I format the output, please? celsius = input(“What is the temperature in Celsius: “) farenheit = float(celsius)*1.8+32 print(f”The temperature in Farenheit is: {farenheit}”) Thanks in advance. submitted by /u/KazzJen [link] [comments]

Read more

Create a project / app together /u/Sephass Python Education

Create a project / app together /u/Sephass Python Education

Hi guys,

Crazy idea. I see a lot of posts from people who struggle to find a real project or good problem after getting to intermediate Python level and completing several of the established courses.

Myself, I’m in a similar situation. In my 30’s, with an already established career as non-dev in the tech domain, who wants to develop some solid coding/developer skills and doesn’t have opportunities to apply this stuff in real-time development. Let’s be honest – I’m not dropping out from what I’m doing for a living anytime soon, but would still love to build competency in coding and get more and more skilled in this area in my free time.

I’m thinking – why not get together and work on something as a group? It’s usually really hard to come up with your own idea and the whole solution on your own, whilst this could be a great motivator and opportunity to meet some like-minded people at similar stages in their journey, which could prove useful any time in the future even if this is just for fun and doesn’t necessarily work out as a full-fledged app or project.

I already have an idea for building a solution for summarising and dissecting podcasts using AI tools and have a rough outline of how I would like to build it. Speaking frankly, I think I have a decent vision of where I want this to go and what is my itch, but with limited time on my hands and other commitments it would be just a huge amount of work for a first bigger project and I would prefer to iterate faster and bring in someone else to contribute as well (better together). It would also make me more accountable if I have someone else working on this alongside me.

I hope this is not too much of an offtopic in this sub. If you’re reading this and you feel like this is something interesting for you, please shoot me a DM and we can check if we vibe and have similar expectations. I hope it’s obvious – I don’t offer any remuneration for this and don’t expect this to become a start-up or for profit. It’s either for someone who feels like they are already somewhere with their skills but lack project idea / real life application or someone who already brings dev experience and is still enthusiastic to work on stuff on the side for fun of building something and meeting new people.

Let’s see how this goes? Happy Xmas to you all!

submitted by /u/Sephass
[link] [comments]

​r/learnpython Hi guys, Crazy idea. I see a lot of posts from people who struggle to find a real project or good problem after getting to intermediate Python level and completing several of the established courses. Myself, I’m in a similar situation. In my 30’s, with an already established career as non-dev in the tech domain, who wants to develop some solid coding/developer skills and doesn’t have opportunities to apply this stuff in real-time development. Let’s be honest – I’m not dropping out from what I’m doing for a living anytime soon, but would still love to build competency in coding and get more and more skilled in this area in my free time. I’m thinking – why not get together and work on something as a group? It’s usually really hard to come up with your own idea and the whole solution on your own, whilst this could be a great motivator and opportunity to meet some like-minded people at similar stages in their journey, which could prove useful any time in the future even if this is just for fun and doesn’t necessarily work out as a full-fledged app or project. I already have an idea for building a solution for summarising and dissecting podcasts using AI tools and have a rough outline of how I would like to build it. Speaking frankly, I think I have a decent vision of where I want this to go and what is my itch, but with limited time on my hands and other commitments it would be just a huge amount of work for a first bigger project and I would prefer to iterate faster and bring in someone else to contribute as well (better together). It would also make me more accountable if I have someone else working on this alongside me. I hope this is not too much of an offtopic in this sub. If you’re reading this and you feel like this is something interesting for you, please shoot me a DM and we can check if we vibe and have similar expectations. I hope it’s obvious – I don’t offer any remuneration for this and don’t expect this to become a start-up or for profit. It’s either for someone who feels like they are already somewhere with their skills but lack project idea / real life application or someone who already brings dev experience and is still enthusiastic to work on stuff on the side for fun of building something and meeting new people. Let’s see how this goes? Happy Xmas to you all! submitted by /u/Sephass [link] [comments] 

Hi guys,

Crazy idea. I see a lot of posts from people who struggle to find a real project or good problem after getting to intermediate Python level and completing several of the established courses.

Myself, I’m in a similar situation. In my 30’s, with an already established career as non-dev in the tech domain, who wants to develop some solid coding/developer skills and doesn’t have opportunities to apply this stuff in real-time development. Let’s be honest – I’m not dropping out from what I’m doing for a living anytime soon, but would still love to build competency in coding and get more and more skilled in this area in my free time.

I’m thinking – why not get together and work on something as a group? It’s usually really hard to come up with your own idea and the whole solution on your own, whilst this could be a great motivator and opportunity to meet some like-minded people at similar stages in their journey, which could prove useful any time in the future even if this is just for fun and doesn’t necessarily work out as a full-fledged app or project.

I already have an idea for building a solution for summarising and dissecting podcasts using AI tools and have a rough outline of how I would like to build it. Speaking frankly, I think I have a decent vision of where I want this to go and what is my itch, but with limited time on my hands and other commitments it would be just a huge amount of work for a first bigger project and I would prefer to iterate faster and bring in someone else to contribute as well (better together). It would also make me more accountable if I have someone else working on this alongside me.

I hope this is not too much of an offtopic in this sub. If you’re reading this and you feel like this is something interesting for you, please shoot me a DM and we can check if we vibe and have similar expectations. I hope it’s obvious – I don’t offer any remuneration for this and don’t expect this to become a start-up or for profit. It’s either for someone who feels like they are already somewhere with their skills but lack project idea / real life application or someone who already brings dev experience and is still enthusiastic to work on stuff on the side for fun of building something and meeting new people.

Let’s see how this goes? Happy Xmas to you all!

submitted by /u/Sephass
[link] [comments]  Hi guys, Crazy idea. I see a lot of posts from people who struggle to find a real project or good problem after getting to intermediate Python level and completing several of the established courses. Myself, I’m in a similar situation. In my 30’s, with an already established career as non-dev in the tech domain, who wants to develop some solid coding/developer skills and doesn’t have opportunities to apply this stuff in real-time development. Let’s be honest – I’m not dropping out from what I’m doing for a living anytime soon, but would still love to build competency in coding and get more and more skilled in this area in my free time. I’m thinking – why not get together and work on something as a group? It’s usually really hard to come up with your own idea and the whole solution on your own, whilst this could be a great motivator and opportunity to meet some like-minded people at similar stages in their journey, which could prove useful any time in the future even if this is just for fun and doesn’t necessarily work out as a full-fledged app or project. I already have an idea for building a solution for summarising and dissecting podcasts using AI tools and have a rough outline of how I would like to build it. Speaking frankly, I think I have a decent vision of where I want this to go and what is my itch, but with limited time on my hands and other commitments it would be just a huge amount of work for a first bigger project and I would prefer to iterate faster and bring in someone else to contribute as well (better together). It would also make me more accountable if I have someone else working on this alongside me. I hope this is not too much of an offtopic in this sub. If you’re reading this and you feel like this is something interesting for you, please shoot me a DM and we can check if we vibe and have similar expectations. I hope it’s obvious – I don’t offer any remuneration for this and don’t expect this to become a start-up or for profit. It’s either for someone who feels like they are already somewhere with their skills but lack project idea / real life application or someone who already brings dev experience and is still enthusiastic to work on stuff on the side for fun of building something and meeting new people. Let’s see how this goes? Happy Xmas to you all! submitted by /u/Sephass [link] [comments]

Read more

Weird subprocess.run behaviour /u/Entraxipy Python Education

Weird subprocess.run behaviour /u/Entraxipy Python Education

So I’m making a small test project to learn python better and for some reason, when I run it, it prints the command out, and then it seems like subprocess.run freezes as nothing else happens. When I copy the command and paste it in command prompt however, the command works perfectly fine. When an error is raised, the subprocess.run returns a non-zero return code and my program continues as normal. What is happening?

command is typically structured as a multiline list of valid terminal commands.

import os import subprocess import gptinterface as ChatGPT import time initial_prompt = r""" ommited for clarity """ workfolder = r"C:UsersRoberPycharmProjectsAI_coderworkplace" command = ChatGPT.send_msg(initial_prompt) while True: command = command.strip("`").strip() print(">>> "+repr(command)+"") if command == "help": command = ChatGPT.send_msg(initial_prompt) continue start = time.time() result = subprocess.run(str(command), cwd=workfolder, shell=True, capture_output=True, env=os.environ, text=True, timeout=5) end = time.time() print("finished command") if result.returncode == 0: time_taken = (end-start)*1000 print(result.stdout) command = ChatGPT.send_msg(f"Success:n{result.stdout}nnTook {time_taken:.1f} msnSend 'help' if you want a reminder of your target.") else: print(result.stderr) command = ChatGPT.send_msg("Error:n"+result.stderr+"nSend 'help' if you want a reminder of your target.") 

submitted by /u/Entraxipy
[link] [comments]

​r/learnpython So I’m making a small test project to learn python better and for some reason, when I run it, it prints the command out, and then it seems like subprocess.run freezes as nothing else happens. When I copy the command and paste it in command prompt however, the command works perfectly fine. When an error is raised, the subprocess.run returns a non-zero return code and my program continues as normal. What is happening? command is typically structured as a multiline list of valid terminal commands. import os import subprocess import gptinterface as ChatGPT import time initial_prompt = r””” ommited for clarity “”” workfolder = r”C:UsersRoberPycharmProjectsAI_coderworkplace” command = ChatGPT.send_msg(initial_prompt) while True: command = command.strip(“`”).strip() print(“>>> “+repr(command)+””) if command == “help”: command = ChatGPT.send_msg(initial_prompt) continue start = time.time() result = subprocess.run(str(command), cwd=workfolder, shell=True, capture_output=True, env=os.environ, text=True, timeout=5) end = time.time() print(“finished command”) if result.returncode == 0: time_taken = (end-start)*1000 print(result.stdout) command = ChatGPT.send_msg(f”Success:n{result.stdout}nnTook {time_taken:.1f} msnSend ‘help’ if you want a reminder of your target.”) else: print(result.stderr) command = ChatGPT.send_msg(“Error:n”+result.stderr+”nSend ‘help’ if you want a reminder of your target.”) submitted by /u/Entraxipy [link] [comments] 

So I’m making a small test project to learn python better and for some reason, when I run it, it prints the command out, and then it seems like subprocess.run freezes as nothing else happens. When I copy the command and paste it in command prompt however, the command works perfectly fine. When an error is raised, the subprocess.run returns a non-zero return code and my program continues as normal. What is happening?

command is typically structured as a multiline list of valid terminal commands.

import os import subprocess import gptinterface as ChatGPT import time initial_prompt = r""" ommited for clarity """ workfolder = r"C:UsersRoberPycharmProjectsAI_coderworkplace" command = ChatGPT.send_msg(initial_prompt) while True: command = command.strip("`").strip() print(">>> "+repr(command)+"") if command == "help": command = ChatGPT.send_msg(initial_prompt) continue start = time.time() result = subprocess.run(str(command), cwd=workfolder, shell=True, capture_output=True, env=os.environ, text=True, timeout=5) end = time.time() print("finished command") if result.returncode == 0: time_taken = (end-start)*1000 print(result.stdout) command = ChatGPT.send_msg(f"Success:n{result.stdout}nnTook {time_taken:.1f} msnSend 'help' if you want a reminder of your target.") else: print(result.stderr) command = ChatGPT.send_msg("Error:n"+result.stderr+"nSend 'help' if you want a reminder of your target.") 

submitted by /u/Entraxipy
[link] [comments]  So I’m making a small test project to learn python better and for some reason, when I run it, it prints the command out, and then it seems like subprocess.run freezes as nothing else happens. When I copy the command and paste it in command prompt however, the command works perfectly fine. When an error is raised, the subprocess.run returns a non-zero return code and my program continues as normal. What is happening? command is typically structured as a multiline list of valid terminal commands. import os import subprocess import gptinterface as ChatGPT import time initial_prompt = r””” ommited for clarity “”” workfolder = r”C:UsersRoberPycharmProjectsAI_coderworkplace” command = ChatGPT.send_msg(initial_prompt) while True: command = command.strip(“`”).strip() print(“>>> “+repr(command)+””) if command == “help”: command = ChatGPT.send_msg(initial_prompt) continue start = time.time() result = subprocess.run(str(command), cwd=workfolder, shell=True, capture_output=True, env=os.environ, text=True, timeout=5) end = time.time() print(“finished command”) if result.returncode == 0: time_taken = (end-start)*1000 print(result.stdout) command = ChatGPT.send_msg(f”Success:n{result.stdout}nnTook {time_taken:.1f} msnSend ‘help’ if you want a reminder of your target.”) else: print(result.stderr) command = ChatGPT.send_msg(“Error:n”+result.stderr+”nSend ‘help’ if you want a reminder of your target.”) submitted by /u/Entraxipy [link] [comments]

Read more

How to run a .py without aide /u/Impressive_Nose7329 Python Education

How to run a .py without aide /u/Impressive_Nose7329 Python Education

Example if I would wanna make a program on someone’s Conputer without them having a IDE installed is that possible or do I need them to first have a Python IDE installed for it to run maybe on the background.

submitted by /u/Impressive_Nose7329
[link] [comments]

​r/learnpython Example if I would wanna make a program on someone’s Conputer without them having a IDE installed is that possible or do I need them to first have a Python IDE installed for it to run maybe on the background. submitted by /u/Impressive_Nose7329 [link] [comments] 

Example if I would wanna make a program on someone’s Conputer without them having a IDE installed is that possible or do I need them to first have a Python IDE installed for it to run maybe on the background.

submitted by /u/Impressive_Nose7329
[link] [comments]  Example if I would wanna make a program on someone’s Conputer without them having a IDE installed is that possible or do I need them to first have a Python IDE installed for it to run maybe on the background. submitted by /u/Impressive_Nose7329 [link] [comments]

Read more

How to upload files from a local folder to Sharepoint folder daily using python and task manager maybe?? /u/EasyBox5718 Python Education

How to upload files from a local folder to Sharepoint folder daily using python and task manager maybe?? /u/EasyBox5718 Python Education

I’m looking for a way to automatically upload files daily to Sharepoint folder using python, .bat files, task manager or whatever in a specific time daily.

submitted by /u/EasyBox5718
[link] [comments]

​r/learnpython I’m looking for a way to automatically upload files daily to Sharepoint folder using python, .bat files, task manager or whatever in a specific time daily. submitted by /u/EasyBox5718 [link] [comments] 

I’m looking for a way to automatically upload files daily to Sharepoint folder using python, .bat files, task manager or whatever in a specific time daily.

submitted by /u/EasyBox5718
[link] [comments]  I’m looking for a way to automatically upload files daily to Sharepoint folder using python, .bat files, task manager or whatever in a specific time daily. submitted by /u/EasyBox5718 [link] [comments]

Read more

Printing text within ASCII /u/Twigzywik Python Education

Printing text within ASCII /u/Twigzywik Python Education

Hello, I need some help on some ideas on how to go about this. I want to print a box made with | and –

The goal here is to print text within the box without disturbing its geometry, but not printing it all at the same time which would be rather easy. I want to do a type writer effect within the box. How can I go about this? Printing line by line kind of makes the end of the box, and the rest of the box not print until it finishes the print for the typewriter text.

submitted by /u/Twigzywik
[link] [comments]

​r/learnpython Hello, I need some help on some ideas on how to go about this. I want to print a box made with | and – The goal here is to print text within the box without disturbing its geometry, but not printing it all at the same time which would be rather easy. I want to do a type writer effect within the box. How can I go about this? Printing line by line kind of makes the end of the box, and the rest of the box not print until it finishes the print for the typewriter text. submitted by /u/Twigzywik [link] [comments] 

Hello, I need some help on some ideas on how to go about this. I want to print a box made with | and –

The goal here is to print text within the box without disturbing its geometry, but not printing it all at the same time which would be rather easy. I want to do a type writer effect within the box. How can I go about this? Printing line by line kind of makes the end of the box, and the rest of the box not print until it finishes the print for the typewriter text.

submitted by /u/Twigzywik
[link] [comments]  Hello, I need some help on some ideas on how to go about this. I want to print a box made with | and – The goal here is to print text within the box without disturbing its geometry, but not printing it all at the same time which would be rather easy. I want to do a type writer effect within the box. How can I go about this? Printing line by line kind of makes the end of the box, and the rest of the box not print until it finishes the print for the typewriter text. submitted by /u/Twigzywik [link] [comments]

Read more

Make a global venv in uv? Use numpy from anywhere? /u/Informal-Addendum435 Python Education

Make a global venv in uv? Use numpy from anywhere? /u/Informal-Addendum435 Python Education

I have a dream that one day I will be able to uv run python in any directory and have numpy available in the REPL.

How can I achieve that?

I would imagine uv run --venv=numpy python would be cool

submitted by /u/Informal-Addendum435
[link] [comments]

​r/learnpython I have a dream that one day I will be able to uv run python in any directory and have numpy available in the REPL. How can I achieve that? I would imagine uv run –venv=numpy python would be cool submitted by /u/Informal-Addendum435 [link] [comments] 

I have a dream that one day I will be able to uv run python in any directory and have numpy available in the REPL.

How can I achieve that?

I would imagine uv run --venv=numpy python would be cool

submitted by /u/Informal-Addendum435
[link] [comments]  I have a dream that one day I will be able to uv run python in any directory and have numpy available in the REPL. How can I achieve that? I would imagine uv run –venv=numpy python would be cool submitted by /u/Informal-Addendum435 [link] [comments]

Read more

Slider Position Resets After Song Playback and Manual Update in Music Player App (Pygame + Tkinter) /u/PFG_Gamer Python Education

Slider Position Resets After Song Playback and Manual Update in Music Player App (Pygame + Tkinter) /u/PFG_Gamer Python Education

I was making an music app player and was trying to implement a function where the user can seek forward or backward using the seekbar. Whenever I tried to click anywhere on the seekbar, my music position would change according to the value of the seekbar where I clicked. But the seekbar starts back from 0 whenever I try to skip in the song. How to fix this? The below one is my code.(Ignore the format, I am not much experienced python developer)

import io from pygame import mixer from mutagen.mp3 import MP3 # Variables current_song = "songs/middle_of_night.mp3" has_song_started = False is_song_playing = False is_slider_dragging = False # Get the current song length audio = MP3(current_song) total_duration = audio.info.length # Programming Code mixer.init() mixer.music.load(current_song) def play_song(): global has_song_started global is_song_playing mixer.music.play() has_song_started = True is_song_playing = True def pause(): global is_song_playing mixer.music.pause() is_song_playing = False def resume(): global is_song_playing mixer.music.unpause() is_song_playing = True def playback_slider_event(value): global total_duration music_pos = (float(value)/100)*total_duration music_pos = music_pos * 1000 print(f"value = {value}") print(f"music_pos = {music_pos}") # mixer.music.stop() # mixer.music.play(start=music_pos/1000) mixer.music.set_pos(music_pos/1000) # print(f"percentage = {percentage}") slider.set(value) # GUI slider = ctk.CTkSlider(home, from_=0, to=100, command=playback_slider_event, width=600) slider.pack(pady=30) # Add padding around the slider # Programming Code def set_playback_slider(): global is_slider_dragging if not is_slider_dragging: current_position = mixer.music.get_pos()/1000 percentage = (current_position/total_duration)*100 print(percentage) slider.set(percentage) app.after(1000, set_playback_slider) def slider_drag_start(event): global is_slider_dragging is_slider_dragging = True def slider_drag_end(event): global is_slider_dragging is_slider_dragging = False # Bind the slider drag events slider.bind("<ButtonPress-1>", slider_drag_start) # When slider dragging starts slider.bind("<ButtonRelease-1>", slider_drag_end) # When slider dragging ends change_play_button_command() set_playback_slider() app.mainloop() 

submitted by /u/PFG_Gamer
[link] [comments]

​r/learnpython I was making an music app player and was trying to implement a function where the user can seek forward or backward using the seekbar. Whenever I tried to click anywhere on the seekbar, my music position would change according to the value of the seekbar where I clicked. But the seekbar starts back from 0 whenever I try to skip in the song. How to fix this? The below one is my code.(Ignore the format, I am not much experienced python developer) import io from pygame import mixer from mutagen.mp3 import MP3 # Variables current_song = “songs/middle_of_night.mp3″ has_song_started = False is_song_playing = False is_slider_dragging = False # Get the current song length audio = MP3(current_song) total_duration = audio.info.length # Programming Code mixer.init() mixer.music.load(current_song) def play_song(): global has_song_started global is_song_playing mixer.music.play() has_song_started = True is_song_playing = True def pause(): global is_song_playing mixer.music.pause() is_song_playing = False def resume(): global is_song_playing mixer.music.unpause() is_song_playing = True def playback_slider_event(value): global total_duration music_pos = (float(value)/100)*total_duration music_pos = music_pos * 1000 print(f”value = {value}”) print(f”music_pos = {music_pos}”) # mixer.music.stop() # mixer.music.play(start=music_pos/1000) mixer.music.set_pos(music_pos/1000) # print(f”percentage = {percentage}”) slider.set(value) # GUI slider = ctk.CTkSlider(home, from_=0, to=100, command=playback_slider_event, width=600) slider.pack(pady=30) # Add padding around the slider # Programming Code def set_playback_slider(): global is_slider_dragging if not is_slider_dragging: current_position = mixer.music.get_pos()/1000 percentage = (current_position/total_duration)*100 print(percentage) slider.set(percentage) app.after(1000, set_playback_slider) def slider_drag_start(event): global is_slider_dragging is_slider_dragging = True def slider_drag_end(event): global is_slider_dragging is_slider_dragging = False # Bind the slider drag events slider.bind(“<ButtonPress-1>”, slider_drag_start) # When slider dragging starts slider.bind(“<ButtonRelease-1>”, slider_drag_end) # When slider dragging ends change_play_button_command() set_playback_slider() app.mainloop() submitted by /u/PFG_Gamer [link] [comments] 

I was making an music app player and was trying to implement a function where the user can seek forward or backward using the seekbar. Whenever I tried to click anywhere on the seekbar, my music position would change according to the value of the seekbar where I clicked. But the seekbar starts back from 0 whenever I try to skip in the song. How to fix this? The below one is my code.(Ignore the format, I am not much experienced python developer)

import io from pygame import mixer from mutagen.mp3 import MP3 # Variables current_song = "songs/middle_of_night.mp3" has_song_started = False is_song_playing = False is_slider_dragging = False # Get the current song length audio = MP3(current_song) total_duration = audio.info.length # Programming Code mixer.init() mixer.music.load(current_song) def play_song(): global has_song_started global is_song_playing mixer.music.play() has_song_started = True is_song_playing = True def pause(): global is_song_playing mixer.music.pause() is_song_playing = False def resume(): global is_song_playing mixer.music.unpause() is_song_playing = True def playback_slider_event(value): global total_duration music_pos = (float(value)/100)*total_duration music_pos = music_pos * 1000 print(f"value = {value}") print(f"music_pos = {music_pos}") # mixer.music.stop() # mixer.music.play(start=music_pos/1000) mixer.music.set_pos(music_pos/1000) # print(f"percentage = {percentage}") slider.set(value) # GUI slider = ctk.CTkSlider(home, from_=0, to=100, command=playback_slider_event, width=600) slider.pack(pady=30) # Add padding around the slider # Programming Code def set_playback_slider(): global is_slider_dragging if not is_slider_dragging: current_position = mixer.music.get_pos()/1000 percentage = (current_position/total_duration)*100 print(percentage) slider.set(percentage) app.after(1000, set_playback_slider) def slider_drag_start(event): global is_slider_dragging is_slider_dragging = True def slider_drag_end(event): global is_slider_dragging is_slider_dragging = False # Bind the slider drag events slider.bind("<ButtonPress-1>", slider_drag_start) # When slider dragging starts slider.bind("<ButtonRelease-1>", slider_drag_end) # When slider dragging ends change_play_button_command() set_playback_slider() app.mainloop() 

submitted by /u/PFG_Gamer
[link] [comments]  I was making an music app player and was trying to implement a function where the user can seek forward or backward using the seekbar. Whenever I tried to click anywhere on the seekbar, my music position would change according to the value of the seekbar where I clicked. But the seekbar starts back from 0 whenever I try to skip in the song. How to fix this? The below one is my code.(Ignore the format, I am not much experienced python developer) import io from pygame import mixer from mutagen.mp3 import MP3 # Variables current_song = “songs/middle_of_night.mp3″ has_song_started = False is_song_playing = False is_slider_dragging = False # Get the current song length audio = MP3(current_song) total_duration = audio.info.length # Programming Code mixer.init() mixer.music.load(current_song) def play_song(): global has_song_started global is_song_playing mixer.music.play() has_song_started = True is_song_playing = True def pause(): global is_song_playing mixer.music.pause() is_song_playing = False def resume(): global is_song_playing mixer.music.unpause() is_song_playing = True def playback_slider_event(value): global total_duration music_pos = (float(value)/100)*total_duration music_pos = music_pos * 1000 print(f”value = {value}”) print(f”music_pos = {music_pos}”) # mixer.music.stop() # mixer.music.play(start=music_pos/1000) mixer.music.set_pos(music_pos/1000) # print(f”percentage = {percentage}”) slider.set(value) # GUI slider = ctk.CTkSlider(home, from_=0, to=100, command=playback_slider_event, width=600) slider.pack(pady=30) # Add padding around the slider # Programming Code def set_playback_slider(): global is_slider_dragging if not is_slider_dragging: current_position = mixer.music.get_pos()/1000 percentage = (current_position/total_duration)*100 print(percentage) slider.set(percentage) app.after(1000, set_playback_slider) def slider_drag_start(event): global is_slider_dragging is_slider_dragging = True def slider_drag_end(event): global is_slider_dragging is_slider_dragging = False # Bind the slider drag events slider.bind(“<ButtonPress-1>”, slider_drag_start) # When slider dragging starts slider.bind(“<ButtonRelease-1>”, slider_drag_end) # When slider dragging ends change_play_button_command() set_playback_slider() app.mainloop() submitted by /u/PFG_Gamer [link] [comments]

Read more