Форум сайта python.su
0
Как мне сделать чтобы файл(f, savepath.txt) используемый в программе был доступен во всех функций if их для чтения или для записи?
#import's #################### import os import os.path import tkinter from pygame import mixer from tkinter import * from tkinter import filedialog ############################## #installize MGI = tkinter.Tk() MGI.title("LISTE BY ME 0.0.2") MGI.geometry('640x500') pryoimge1 = PhotoImage(file = "folde1r.png") pryoimge2 = PhotoImage(file = "mp_btns_play.png") PathSelect_button_icon = pryoimge1.subsample(8,8) PlayTreak_button_icon = pryoimge2.subsample(10,10) #func's def mp3_listbox1(dirctory): check_file = os.path.exists('savepath.txt') if check_file == False: f = open("savepath.txt", 'w') 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) if check_file == True: z = (f.read()) mp3_listbox.insert(z) def Play_Treak(selcted_file): mixer.init() mixer.music.load(selcted_file) mixer.music.play() def Select_folder(): dirctory = filedialog.askdirectory() mp3_listbox1(dirctory) def selct_file(): selcted_file = mp3_listbox.get(ACTIVE) Play_Treak(selcted_file) #interface 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) #placing widgts PathSelect_button.place(x = 10, y = 1) mp3_listbox.place(x = 20, y = 100) PlayTreak_button.place(x = 10, y= 56 ) #run tkinter MGI.mainloop()
Офлайн
221
tempkoder12
эх, вот смотрю я на вас, и думаю что наверное все такие нужно поучиться программировать. Ну в вашем стиле кода нужны глобальные переменные. И да про них написано в учебниках, возможно где нибудь возле “Области видимости”
Офлайн