Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44895
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| 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; 'mrab': 0.05; 'attribute': 0.07; 'class,': 0.07; 'subject:code': 0.07; 'subject:file': 0.07; 'tkinter': 0.07; 'instance.': 0.09; '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; 'escribi\xf3:': 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; 'mayo': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'subject: \n ': 0.16; 'tk()': 0.16; 'subject:python': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'starts': 0.20; 'thanks.': 0.20; 'programming': 0.22; 'import': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'library,': 0.24; 'url:moin': 0.24; '(or': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'code': 0.31; 'url:wiki': 0.31; 'file': 0.32; 'text': 0.33; 'url:python': 0.33; 'subject:the': 0.34; 'could': 0.34; 'problem.': 0.35; 'skip:s 30': 0.35; 'case,': 0.35; 'one,': 0.35; 'point.': 0.35; 'test': 0.35; 'but': 0.35; 'doing': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'wrong': 0.37; 'button': 0.38; 'gmail': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'simple': 0.61; 'making': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.64; 'details': 0.65; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'subject:this': 0.83; 'methodology.': 0.84; 'played': 0.84; 'presumably': 0.84; 'reply- to:addr:python.org': 0.84; 'sonido': 0.84; '2013': 0.98 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=TZ6v63gh 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=bvze1IrMiVzmFUV1wxUA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Tue, 07 May 2013 15:57:59 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| 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> <mailman.1402.1367924006.3114.python-list@python.org> <85771dda-4289-4cfb-a96f-23809664913e@googlegroups.com> |
| In-Reply-To | <85771dda-4289-4cfb-a96f-23809664913e@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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1413.1367938681.3114.python-list@python.org> (permalink) |
| Lines | 41 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1367938681 news.xs4all.nl 15970 [2001:888:2000:d::a6]:36834 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44895 |
Show key headers only | View raw
On 07/05/2013 14:56, cheirasacan@gmail.com wrote:
> El martes, 7 de mayo de 2013 12:53:25 UTC+2, MRAB escribió:
>> 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).
>
> Thanks. A global use of 'sonido' fix the problem. The garbage collector must be the point. But this code is part of a longer project. What can i do to fix it without the use of globals? I will use more functions like this, and i would like to keep learning python as well good programming methodology.
> Thanks.
>
Presumably the details of the window are (or will be) hidden away in a
class, so you could make 'file' an attribute of an instance.
Also, please read this:
http://wiki.python.org/moin/GoogleGroupsPython
because gmail insists on adding extra linebreaks, which can be somewhat
annoying.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why sfml does not play the file inside a function in this python code? cheirasacan@gmail.com - 2013-05-07 02:27 -0700
Re: Why sfml does not play the file inside a function in this python code? MRAB <python@mrabarnett.plus.com> - 2013-05-07 11:53 +0100
Re: Why sfml does not play the file inside a function in this python code? cheirasacan@gmail.com - 2013-05-07 06:56 -0700
Re: Why sfml does not play the file inside a function in this python code? MRAB <python@mrabarnett.plus.com> - 2013-05-07 15:57 +0100
Re: Why sfml does not play the file inside a function in this python code? cheirasacan@gmail.com - 2013-05-07 13:02 -0700
Re: Why sfml does not play the file inside a function in this python code? Chris Angelico <rosuav@gmail.com> - 2013-05-08 01:06 +1000
dist-packages or site-packages in Python 3.2 ? Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-05-07 19:03 +0200
csiph-web