im trying to build a program (using pysimplegui) which contains a few buttons (play, stop, pause, next, previous) as you can see. and when i press "next" its stopping for some time and then the same music continues (i dont press "previous" because i know that will cause problem 0 - 1 = -1).
`
global n
n = 0
media_player = vlc.MediaPlayer()
url = ['http://cast.radiogroup.com.ua:8000/avtoradio', 'http://listen.rpfm.ru:9000/premium128', 'http://cast.loungefm.com.ua/terrace128']
media_player.set_mrl(url[n])
if event == 'play':
media_player.play()
if event == 'stop':
media_player.stop()
if event == 'pause':
media_player.pause()
if event == 'next':
global n
n + 1
media_player.set_mrl(url[n])
media_player.play()
if event == 'previous':
n - 1
media_player.set_mrl(url[n])
media_player.play()
`
ive tried to google this problem
i didnt find the documentation
im trying to run it in a bit different way, using `
import vlc
playlist_url = ['http://cast.radiogroup.com.ua:8000/avtoradio', 'http://listen.rpfm.ru:9000/premium128', 'http://cast.loungefm.com.ua/terrace128']
n = int(input())
instance = vlc.Instance('--intf dummy')
player = instance.media_list_player_new()
media = instance.media_list_new(playlist_url[n])
player.set_media_list(media)
player.play()
`
but it returns
[0000027223bc32e0] filesystem stream error: cannot open file C:\Users\dadva\Desktop\Project\h (No such file or directory)
[0000027223ba3220] main input error: Your input can't be opened
[0000027223ba3220] main input error: VLC is unable to open the MRL 'file:///C:/Users/dadva/Desktop/Project/h'. Check the log for details.
Demo Code
import vlc
import PySimpleGUI as sg
playlist_url = [
'http://cast.radiogroup.com.ua:8000/avtoradio',
'http://listen.rpfm.ru:9000/premium128',
'http://cast.loungefm.com.ua/terrace128',
]
n, m = 0, len(playlist_url)
player = vlc.MediaPlayer()
player.set_mrl(playlist_url[n])
player.play()
layout = [[sg.Button('PREV'), sg.Button('NEXT')]]
window = sg.Window('VLC Player', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event in ('PREV', 'NEXT'):
n = (n+1) % m if event == 'NEXT' else (n-1) % m
player.set_mrl(playlist_url[n])
player.play()
player.stop()
window.close()
Related
I'm writing a script for game, i need to bind some key for pressing right click for three times. I can do it, but if i will use it in game i can press WASD or something else when i using hotkey and it doesn't work.
My code here :
import keyboard
import mouse
import time
iswork = False
def work():
global iswork
if iswork:
iswork = False
print("Script deactivated")
else:
iswork = True
print("Script activated")
keyboard.add_hotkey("F4",work)
def RRR():
if iswork :
for i in range(3):
mouse.right_click()
time.sleep(0.05)
bind = input("Bind for Right - Right - Right :")
#keyboard.add_hotkey(bind,RRR)
while iswork:
if keyboard.is_pressed("x") and len(keyboard._pressed_events) >= 1:
RRR()
elif keyboard.is_pressed("x"):
RRR()
while True :
count = 0
So I want to start a project that records my keyboard input and mouse movement for a sandbox PC games. I love farming, however whether I'm tired, and taking a short break to make a coffee or have a phone call. When I come back my farm gets annihilated.
I tried and made this one, but it seems not to work. Any way to make it better with the possibility to implement the recorded inputs in a loop function?
import pyautogui
def record_movement():
# Initialize variables to store mouse and keyboard events
mouse_events = []
keyboard_events = []
# Start recording mouse and keyboard events
pyautogui.PAUSE = 0.001 # Set a small pause to record events more accurately
pyautogui.FAILSAFE = False # Disable failsafe feature to allow for recording
recording = True
while recording:
event = pyautogui.getEvent()
if event.event_type == 'MouseMove':
mouse_events.append(event)
elif event.event_type == 'KeyDown':
keyboard_events.append(event)
elif event.event_type == 'KeyUp':
keyboard_events.append(event)
elif event.event_type == 'Quit':
recording = False
return mouse_events, keyboard_events
def replay_movement(mouse_events, keyboard_events):
# Replay recorded mouse and keyboard events
for event in mouse_events:
pyautogui.moveTo(event.x, event.y)
for event in keyboard_events:
if event.event_type == 'KeyDown':
pyautogui.press(event.name)
elif event.event_type == 'KeyUp':
pyautogui.keyUp(event.name)
# Test:
mouse_events, keyboard_events = record_movement()
replay_movement(mouse_events, keyboard_events)
when i press "submit" the program freezes can you guys please help me. I am new to pysimplegui and am trying to turn one of my practice programs into a gui.
Also could someone tell me how to make the arrows of the "spin" element functional?
If i made some stupid mistakes please do let me know, like i said I am new to this stuff so any help is really appreciated
import time
import PySimpleGUI as sg
import pyautogui as pyautogui
# img_viewer.py
layout=[
[
sg.Text("What do you want to do?"),
sg.Button("Spammer"),sg.Button("Encrypter"),sg.Button("Decrypter"),sg.Button("Password generator"),
sg.Button("Exit")
]
]
window = sg.Window("Multifunctiontool", layout)
layoutspammer=[
[
[sg.Text("Press Start to start the bot.")],
[sg.Text("Press Stop and then enter to stop the bot.")],
[sg.Button("Start"),sg.Button("Stop")]
]
]
layoutspammerwindow=[
[
[sg.Text("How many messages do you want to send?"),sg.Spin(0,key="spammer")],
[sg.Text("How long ist the cooldown? if not there just leave on 0"),sg.Spin(0,key="cooldown")],
[sg.Text("What is your message?"),sg.Input(key="message")],
[sg.Text("Do you want to leave a final message(Write down your message, if no just leave blank)?"),sg.Input(key="final_message")],
[sg.Button("submit"),sg.Button("Exit")]
]
]
layoutspammerwindow2=[
[
[sg.Text("please enter a valid parameter")],
[sg.Button("Continue"), sg.Button("Exit")]
]
]
spammerwindow= sg.Window("spammer",layoutspammer)
spammerwindow2= sg.Window("spammer",layoutspammerwindow,force_toplevel= True)
spammerwindow3= sg.Window("spammer",layoutspammerwindow2)
while True:
event,values=window.read()
if event== "Exit" or event== sg.WIN_CLOSED:
break
if event== "Spammer":
spammer_active = True
while spammer_active is True:
event, values = spammerwindow.read()
if event == "Start":
event, values = spammerwindow2.read()
if event == "Exit" or event == sg.WIN_CLOSED:
break
if event == "submit":
spammer = int(values['spammer'])
cooldown = int(values['cooldown'])
message = (values['message'])
final_message = (values['final_message'])
time.sleep(5)
for xi in range(int(spammer)):
pyautogui.typewrite(message)
time.sleep(int(cooldown))
pyautogui.press('enter')
print(xi)
pyautogui.typewrite(final_message)
pyautogui.press('enter')
break
elif event == "Stop" or event == sg.WIN_CLOSED:
spammer_active = False
else:
event, values = spammerwindow3.read()
if event == "Exit" or sg.WIN_CLOSED:
break
elif event == "Continue":
spammer_active = True
while spammer_active is True:
event, values = spammerwindow.read()
if event == "Start":
event, values = spammerwindow2.read()
if event == "submit":
spammer = int(values['spammer'])
cooldown = int(values['cooldown'])
message = (values['message'])
final_message = (values['final_message'])
time.sleep(5)
for xi in range(int(spammer)):
pyautogui.typewrite(message)
time.sleep(int(cooldown))
pyautogui.press('enter')
print(xi)
pyautogui.typewrite(final_message)
pyautogui.press('enter')
break
window.close()
I have a project that allows the user to make a quiz on their own using some buttons and input
well i even want the user to be able to save their quiz in a file so they can load it in
i don't want something BIG!! a txt file will do..
i am using PySimpleGui and not Tkinter or anything..
i really don't know what i have made till now yet?(sorry i am not great with GUI)
i have a :
Main window
Editor window
And a form window
main window links the editor
editor links the form window
thanks for help in advance
if you need my code too then here
import pysimplegui as sg
layout = [
[sg.Button("Make new Form")],
[sg.Button("Open Form")]
]
window = sg.Window("Python Forms", layout)
def Form_Make():
layout_for_make_form = [
[sg.Button("Add multiple choice question")],
[sg.Button("Save Form")]
# some more items here..
]
make_form_window = sg.Window("Make a Form..", layout_for_make_form)
while True:
events, values = make_form_window.read()
if events == "Add multiple choice question":
pass # this should add a new multi choice question(working on it!)
elif events == "Save Form":
# save a form.. i am stuck on this.. :|
while True:
event,values = windows.read()
if event == "Make new Form":
Form_M()
i really don't know what it is doing yet i will have to make a new file and start from scratch :|
this will work for you :
import PySimpleGUI as sg
import os.path
layout = [
[sg.Button("Make new Form")],
[sg.Button("Open Form")],
[sg.Button("Exit")],
]
windows = sg.Window("Python Forms", layout)
questions = []
def Form_Make():
layout_for_make_form = [
[sg.Button("Add multiple choice question", key='add')],
[sg.Text('file path',size=(10,1)),sg.FileBrowse(key='filepath')],
[sg.Button("Save Form",key='save',visible=False)]
# some more items here..
]
make_form_window = sg.Window("Make a Form..", layout_for_make_form)
while True:
count = False
events, values = make_form_window.read()
if events == "add":
layout_for_question = [
[sg.Text('Must Enter all the filed for save question in file.')],
[sg.Text('Enter Question : ',size=(10,1)),sg.Input(key='question')],
[sg.Text('option1',size=(10,1)),sg.Input(key='option1')],
[sg.Text('option2',size=(10,1)),sg.Input(key='option2')],
[sg.Text('option3',size=(10,1)),sg.Input(key='option3')],
[sg.Text('option4',size=(10,1)),sg.Input(key='option4')],
[sg.Button('add')]
]
make_question_window = sg.Window('question ', layout_for_question)
while True:
events, values = make_question_window.read()
if events == None:
break
elif events == 'add' :
if values['question'] != '' and values['option1'] != '' and values['option2'] != '' and values['option3'] != '' and values['option4'] != '':
questions.append([values['question'],values['option1'],values['option2'],values['option3'],values['option4']])
print('value addded ')
count = True
if count == True:
make_form_window['save'].update(visible=True)
elif events == "save":
print(values['filepath'])
file = values['filepath']
if file != None:
f=open(file,'w+')
for x in questions:
for y in x:
f.write(y + '\n')
f.close()
print('save a form.. i am stuck on this.. :')
elif events == None:
break
while True:
event,values = windows.read()
if event == "Make new Form":
Form_Make()
elif event == 'Exit' or event == None :
break
I want to give the option to the user to play, pause, play next or previous song. If the user does not press anything, the next song in the list should be played automatically. Currently the program halts for the input from the user.
I have tried playing the song in another thread and wait for the user to enter the choice in main thread. But the problem is that main thread waits for the input from the user before playing the next song.
def music(file):
pygame.mixer.music.load(file)
pygame.mixer.music.play()
try:
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(0)
except:
pass
def pause():
print(file + " paused")
pygame.mixer.music.pause()
global set
set = 1
def playsong():
global set
global t1
print ("Playing song named : " + file)
if file != "" and set==0:
t1 = threading.Thread(target = music ,args=(file,))
t1.setName("audio bajao")
t1.start()
ch = 1
song_list = ["song1.mp3","song2.mp3"]
while((i < len(song_list)) and (ch != 5) ):
ch = input("Enter choice ")
file = song_list[i]
if(ch == 1):
playsong()
elif(ch == 2):
ch = 1
pause()
elif(ch == 3):
#play previous song
ch = 1
i -= 2
elif (ch == 4):
#play next song
ch = 1
elif (ch == 5):
break
i += 1
I want the program should play the next song from the list when the song ends if no key is pressed by the user. It should not ask the user again to press the play key to play the next song.
You can try pygame.mixer.get_busy()
To implement this, add some kind of timer variable, I personally prefer tick counters, So...
inactive_ticks = 0
After that, in your main event loop, use pygame.mixer.get_busy() to check if there is music being played or not, then...
if not pygame.mixer.get_busy():
inactive_ticks += 1
if inactive_ticks == 100:
# Play the next song
inactive_ticks = 0
That should work.