[Tutor] mamelauncher
Alan G
alan.gauld at freenet.co.uk
Fri Sep 9 23:51:48 CEST 2005
> I've been working on this for ages and am having real
> problems with getting the wiring for a selected game
> to launch when I click OK.
So what problems are you having? Do you get an error trace?
A superficial glance tells me only that
1) You might find using Tix will simplify your code(scrollable
listboxes etc)
2) Your mailer seems to be adding extra lines, ie I assume the code
isn't
really double spaced? :-)
So whats the specific problem?
Oh yes - and what version of Python?
Alan G.
> I haven't added my error handling yet.
>
> Can anyone help?
>
> I've tried using spawn, system etc etc to no avail.
>
> #Mame Launcher
>
> #GUI launcher for MAME games
>
> #First 'hack' 15th June 2005
>
> #Hacking again 19th August
>
>
>
> import sys, os, subprocess
>
>
>
> from Tkinter import *
>
>
>
> class Mamelaunch(Frame):
>
> """ GUI application to display MAME games in
>
> a list, then launch them. """
>
> def __init__(self, master):
>
> """ Initialize the frame. """
>
> Frame.__init__(self, master)
>
> self.grid()
>
> self.create_widgets()
>
> self.listgames()
>
>
>
> def create_widgets(self):
>
> """ Create button, text, and entry widgets.
> """
>
> # create instruction label
>
> self.inst_lbl = Label(self, text = "Please
> select a game")
>
> self.inst_lbl.grid(row = 0, column = 0,
> columnspan = 2, sticky = W)
>
>
>
> # create label for password
>
> self.pw_lbl = Label(self, text = "Click OK
> when ready ")
>
> self.pw_lbl.grid(row = 12, column = 0, sticky
> = W)
>
>
>
> #create the scrollbar for the listbox
>
> self.yScroll = Scrollbar ( self,
> orient=VERTICAL )
>
> self.yScroll.grid ( row=1, column=1,
> sticky=N+S )
>
>
>
> # create listbox to list games
>
> self.lstbx =Listbox(self, height = 20,
> yscrollcommand=self.yScroll.set, borderwidth = 5,
>
> relief = "sunken",
> highlightcolor = "blue", selectbackground="orange",
>
> selectmode="single")
>
> self.lstbx.grid(row = 1, column =
> 0,sticky=N+S+W)
>
> #lock the vertical scroll to the listbox.
>
> self.yScroll["command"] = self.lstbx.yview
>
>
>
> # create ok button
>
> self.submit_bttn = Button(self, text = "OK")
>
> self.submit_bttn.grid(row = 12, column = 1,
> sticky = S+W)
>
> self.submit_bttn.bind("<Button-1>",
> self.launchmame)
>
>
>
> # create quit button
>
> self.submit_bttn = Button(self, text = "Quit",
> command = self.quit)
>
> self.submit_bttn.grid(row = 12, column = 2,
> sticky = S+W)
>
>
>
> #Try reading list in prior to creating relevant
> widgets
>
> def listgames(self):
>
> """reads list and populates listbox"""
>
> try:
>
> mamefile = open('C:\\mamelist.txt',
> 'r').readlines()
>
> except EnvironmentError:
>
> print "Please check file is in directory"
>
> else:
>
> #split list, populate listbox
>
> for game in mamefile:
>
> game = game.rstrip()
>
> self.lstbx.insert(END, game)
>
>
>
> def launchmame(self, event):
>
> """Mechanism to launch MAME game"""
>
> selection = self.lstbx.curselection()
>
> print selection
>
> os.system("C:\\mame096b\\mame.exe"+""+
> selection)
>
>
>
> # try:
>
> # os.system(echo "game")
>
> # except:
>
> # SystemError(), "Command not found"
>
>
>
> # main
>
> root = Tk()
>
> root.title("MAME Launcher")
>
> root.geometry("220x330")
>
>
>
> app = Mamelaunch(root)
>
>
>
>
>
> root.mainloop()
>
>
>
>
>
> ___________________________________________________________
> To help you stay safe and secure online, we've developed the all new
> Yahoo! Security Centre. http://uk.security.yahoo.com
>
>
More information about the Tutor
mailing list