Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; '480': 0.05; 'subject:code': 0.07; 'subject:file': 0.07; 'tkinter': 0.07; 'returns,': 0.09; 'subject:Why': 0.09; 'python': 0.11; 'def': 0.12; 'windows': 0.15; '1.3.0': 0.16; '3.3,': 0.16; '640,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'function),': 0.16; 'garbage': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject: \n ': 0.16; 'tk()': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'starts': 0.20; 'thanks.': 0.20; 'import': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'library,': 0.24; 'header:In-Reply-To:1': 0.27; 'file': 0.32; 'text': 0.33; 'subject:the': 0.34; 'skip:s 30': 0.35; 'case,': 0.35; 'one,': 0.35; 'received:84': 0.35; 'test': 0.35; 'doing': 0.36; 'subject:?': 0.36; 'should': 0.36; 'wrong': 0.37; 'button': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'simple': 0.61; 'making': 0.63; 'email addr:gmail.com': 0.63; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'subject:this': 0.83; 'played': 0.84; 'reply-to:addr:python.org': 0.84; 'sonido': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=JsTI8qIC c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=7AxPfEIvyrUA:10 a=Mr8ee-VMFlMA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=9aUmtCXPCVcA:10 a=pGLkceISAAAA:8 a=asOf0n92L1sIs5RuyGMA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 X-AUTH: mrabarnett:2500 Date: Tue, 07 May 2013 11:53:25 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Why sfml does not play the file inside a function in this python code? References: <69b77965-5ff5-4c6f-a73d-0826b06353f0@googlegroups.com> In-Reply-To: <69b77965-5ff5-4c6f-a73d-0826b06353f0@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367924006 news.xs4all.nl 15961 [2001:888:2000:d::a6]:50337 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44879 On 07/05/2013 10:27, cheirasacan@gmail.com wrote: > from tkinter import * > import sfml > > > window = Tk() > window.minsize( 640, 480 ) > > > def sonido(): > file = sfml.Music.from_file('poco.ogg') > file.play() > > > test = Button ( window, text = 'Sound test', command=sonido ) > test.place ( x = 10, y = 60) > > window.mainloop() > > > > > Using Windows 7, Python 3.3, sfml 1.3.0 library, the file it is played if i put it out of the function. ¿ what am i doing wrong ? Thanks. > Perhaps what's happening is that sonido starts playing it and then returns, meaning that there's no longer a reference to it ('file' is local to the function), so it's collected by the garbage collector. If that's the case, try keeping a reference to it, perhaps by making 'file' global (in a simple program like this one, using global should be OK).