473,385 Members | 1,461 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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

--

.................................................. ............
Posted thru AtlantisNews - Explore EVERY Newsgroup <
http://www.AtlantisNews.com -- Lightning Fast!!! <
Access the Most Content * No Limits * Best Service <

Nov 22 '05 #1
4 4032
> 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()

Nov 22 '05 #2
> 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()

Nov 22 '05 #3
Nathan Pinno wrote:
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?


Maybe something here:
http://www.pygame.org/wiki/gui

Kent
Nov 22 '05 #4
Nathan Pinno wrote:
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?


Maybe something here:
http://www.pygame.org/wiki/gui

Kent
Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andr? Roberge | last post by:
Sorry about the cryptic subject line, but I wanted to capture the essence of my message in a single line. I am learning Python (which, as everyone know is the best language :-) so that I can...
12
by: Marian Aldenhövel | last post by:
Hi, I am trying to make pygame play music on windows. This simple program: import pygame,time pygame.init() print "Mixer settings", pygame.mixer.get_init() print "Mixer channels",...
3
by: Tim Knauf | last post by:
Hi everyone, I'm glad to have found this list. I've written a small script for my own use which, amongst other things, captures mouse click information from a window containing an image. I used...
2
by: Brent W. Hughes | last post by:
I'm just starting to learn pygame. I write what I think is just about the simplest program that should display a window and then quit. #----------------------------------------------- import sys...
0
by: Nathan Pinno | last post by:
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...
0
by: Lunpa | last post by:
My project: I'm working on a game, where in the ui, it takes the pygame window, and shoves it into a gtk2 socket widget. (gtk2 widgets are generated with glade, with the exception of the socket...
2
by: Blaze Bresko | last post by:
Hi, I am trying to make a game using either livewires or pygame. The game is tetris. Right now I have gotten the program to a point where everything works (as in user input, score, lines, etc),...
4
by: Iacopo.Marmo | last post by:
Hi! I need to manipulate multicolor strings, i.e. strings with a color associated with each letter. Any suggestions?
11
by: globalrev | last post by:
http://www.pygame.org/docs/ref/mixer.html import pygame #pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072) //it complained abiout words= so i guess its only the nbrs...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.