Уведомления

Группа в Telegram: @pythonsu

#1 Ноя. 7, 2018 01:29:59

tempkoder12
Зарегистрирован: 2018-10-29
Сообщения: 13
Репутация: +  0  -
Профиль   Отправить e-mail  

Почему не воспроизводится строки из листбокса взятые из файла?

Цель программы пользователь указывает директория Где расположены его музыка в listbox попадают только .MP3 файлы, далее при нажатии в listbox и на нужный файл и на кнопку плей он воспроизводится, после того программа сохраняет файлы путь который пользователь указал и при каждом новом ее запуска
Берутся строки (пути) из Сохраненного программой файл и вводится в listbox, и пользователю показываются директории из файла.

Ошибка проблема в программе Программа Работает хорошо до того момента когда ей надо считывать информацию из файла то есть при повторном запуске программы она считывает из файла информацию правильно и все директории в файле тоже Правильные но всё-равно трек не воспроизводится, внизу будет прикрепленный код.

Код ошибки:
Traceback (most recent call last):
File “C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py”, line 1705, in __call__
return self.func(*args)
File “SMPMGI.py”, line 63, in selct_file
Play_Treak(selcted_file)
File “SMPMGI.py”, line 48, in Play_Treak
mixer.music.load(selcted_file)
pygame.error: Couldn't open 'CUsers/Koder1554/Music/WATCH DOGS SONG - Digital Shadow.mp3

Код программы:

 #import's ####################
import os
import os.path
import tkinter
from pygame import mixer
from tkinter import *
from tkinter import filedialog
##############################
#installize icon's and files####################
MGI = tkinter.Tk()
MGI.title("LISTER ATV 0.0.3")
MGI.geometry('640x500')
pryoimge1 = PhotoImage(file = "folde1r.png")
pryoimge2 = PhotoImage(file = "mp_btns_play.png")
pryoimge3 = PhotoImage(file = "mp_btns_next.png")
pryoimge4 = PhotoImage(file = "mp_btns_prev.png")
pryoimge5 = PhotoImage(file = "mp_btns_pause.png")
PathSelect_button_icon = pryoimge1.subsample(8,8)
PlayTreak_button_icon = pryoimge2.subsample(10,10)
past_treak_icon = pryoimge4.subsample(10,10)
Next_treak_icon = pryoimge3.subsample(10,10)
Pause_treak_icon = pryoimge5.subsample(10,10)
#################################################
#func's
#if 'savepath.txt' not exsist "run this funcshin"
#make list with only .mp3 files and write/rwrite file if not crate#
def mp3_listbox1(dirctory):
			f = open("savepath.txt", 'w', encoding='utf-8')
			for dirpath, dirnames, filenames in os.walk(dirctory):
				for x in filenames:
					if ".mp3" in x:
						mp3_listbox.insert(END, dirpath + "/" + x)
						f.write(dirpath + "/" + x + "\n")
##################################################################
#play select treak###############
def Play_Treak(selcted_file):
	mixer.init()
	mixer.music.load(selcted_file)
	mixer.music.play()
##################################
#Select folder and file diolog##########
def Select_folder():
	dirctory = filedialog.askdirectory()
	mp3_listbox1(dirctory)
#######################################
#file selecting(get) in list to play func#
def selct_file():
	selcted_file = mp3_listbox.get(ACTIVE)
	Play_Treak(selcted_file)
##########################################
#past treak select(List box clicked element)#
def past_select():
	z = mp3_listbox.index(ACTIVE)
	mp3_listbox.selection_clear(z)
	mp3_listbox.select_set(z-1)
	mp3_listbox.activate(z-1)
	mp3_listbox.selection_anchor(z-1)
	selct_file()
############################################
#Next treak select(get new list elements)###
def next_select():
	z = mp3_listbox.index(ACTIVE)
	mp3_listbox.selection_clear(z)
	mp3_listbox.select_set(z+1)
	mp3_listbox.activate(z+1)
	mp3_listbox.selection_anchor(z+1)
	selct_file()
############################################
#interface button's, Listsbox, and check if file 'savepath.txt' exists###################
PathSelect_button = Button(MGI,  image = PathSelect_button_icon ,command = Select_folder)
PlayTreak_button = Button(MGI, image = PlayTreak_button_icon,command =selct_file)
mp3_listbox = Listbox(MGI, width  = 200 , height = 55)
past_treak = Button(MGI, image = past_treak_icon, command = past_select)
Next_treak = Button(MGI, image = Next_treak_icon, command = next_select)
Pause_treak = Button(MGI, image = Pause_treak_icon)
check_file = os.path.exists('savepath.txt')
if check_file == True:
	f = open("savepath.txt", 'r',encoding='utf-8')
	line = f.readline()
	while line:
		mp3_listbox.insert(END, line)
		line = f.readline() 
##########################################################################################
		
	
#placing buttons, list's. and most witdgts##### 
PathSelect_button.place(x = 10, y = 1)
mp3_listbox.place(x =  20, y = 100)
PlayTreak_button.place(x = 10,  y= 56)
past_treak.place(x = 55, y = 56)
Next_treak.place(x = 100, y = 56)
Pause_treak.place(x = 144, y = 56)
######################################
#run tkinter
MGI.mainloop()




Отредактировано tempkoder12 (Ноя. 7, 2018 01:59:11)

Офлайн

#2 Ноя. 7, 2018 09:34:10

ZerG
Зарегистрирован: 2012-04-05
Сообщения: 2627
Репутация: +  61  -
Профиль   Отправить e-mail  

Почему не воспроизводится строки из листбокса взятые из файла?

для путей используйте os.path.join
И пути в винде вообще имеют прямой слеш
не “Ctmp/mp3” а “C:\tmp\mp3”



Влодение рускай арфаграфией - это как владение кунг-фу: настаящие мастира не преминяют ево бес ниабхадимости

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version