Is there a way to create a button in either pygame or livewires?
Lee Harr
lee at example.com
Sat Nov 19 18:00:12 EST 2005
> 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()
More information about the Python-list
mailing list