Is there a way to create a button in either pygame or livewires?

N

Nathan Pinno

Hey all,

Is there a way to create a button in either pygame or livewires, that is
able to be clicked and when clicked sends a command to restart the program?

Thanks,
Nathan Pinno

--
For great sites go to: http://www.the-web-surfers-store.com
MSN Messenger: falcon3166@hotmail,com
Yahoo! Messenger: spam_swatter31
ICQ: 199020705
AIM: f3mighty
 
L

Lee Harr

Is there a way to create a button in either pygame or livewires, that is
able to be clicked and when clicked sends a command to restart the program?


You could try something like this using pygsear
(http://www.nongnu.org/pygsear/)

The button can call either start() which just makes
a new Game instance in the same process, or
full_restart() which starts a new process and quits
the current one.



from pygsear import Game, Widget
from pygsear.locals import RED


class G(Game.Game):
def initialize(self):
print 'starting up...'

self.button = Widget.SpriteTextButton(self.window, "Restart",
size=40, color=RED, padding=20)
self.events.add(self.button.events)
self.button.set_callback(self.restart)
self.button.set_position((200, 100))
self.sprites.add(self.button)

def restart(self, ev):
print 'restarting...'
#start()
full_restart()
self.quit = True



def start():
g = G()
g.mainloop()


def full_restart():
import os
import sys
cmd = 'python %s &' % sys.argv[0]
os.system(cmd)


if __name__ == '__main__':
start()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top