View Single Post
Old Jul 8th, 2005, 7:24 PM   #1
SaturN
Programmer
 
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4 SaturN is on a distinguished road
Talking YEY!! My First GUI To share with the world!!

Ok, it's my first, so it ain't great!! But it ain't bad either! It does not look perfect, but it's only created on the basics, It's an updated version of my lyric finder..

 
#Lyric Finder.pyw
 
import urllib2, os, sys, random
from Tkinter import *
if "Lyrics" not in os.listdir("C:\\"):
	os.mkdir("C:\Lyrics")
							  
def Search():
	global artist, track
	path = "C:\Lyrics"
	artists = artist.get()
	tracks = track.get()
	artists = artists.replace(' ','%20')
	tracks = tracks.replace(' ','%20')
	url = """http://lyrc.com.ar/en/tema1en.php?songname=%s&artist=%s""" % (tracks,artists)
	opener = urllib2.build_opener()
	opener.addheaders = [('User-agent', 'Mozilla/5.0')]
	lyrics = opener.open(url).read()
	artists = artists.replace("%20","_")
	tracks = tracks.replace("%20","_")
	file = open("%s\%s.html" % (path, "%s by %s"%(tracks, artists)),'w')
	file.write(lyrics)
	os.startfile("%s\%s.html"% (path, "%s by %s"% (tracks, artists)))
	file.close()
	report.configure(text="Displaying Track")
def MakeWindow():
	global lb, artist, track, report
	win = Tk(className=" Lyric Finder powered by Lyrc.com")
	frame1 = Frame(win)
	frame1.pack(side=LEFT)
	frame2 = Frame(win)
	frame2.pack(side=RIGHT)
	artist = StringVar()
	track = StringVar()
	filler = Label(frame1).grid(row=0, column=0)
	artist1 = Entry(frame1, textvariable=artist)
	arr = Label(frame1, text="Enter Artist:")
	arr.grid(row=1, column=1)
	artist1.grid(row=1, column=2)
	fill = Label(frame1).grid(row=2, column=0)
	track1 = Entry(frame1, textvariable=track)
	trr = Label(frame1, text="Enter Track:")
	trr.grid(row=3, column=1)
	track1.grid(row=3, column=2)

	filler1 = Label(frame1, text=' ')
	filler1.grid(row=4, column=2)
	fileo = Button(frame1, text="Open Choosen File", command=OpenFile)
	fileo.grid(row=5, column=2)
	filler2 = Label(frame1, text=' ')
	filler2.grid(row=6, column=2)
	search = Button(frame1, text="Search", command=Search)
	search.grid(row=7, column=2)
	filler3 = Label(frame1)
	filler3.grid(row=8, column=2)		
	report = Label(frame1)
	report.grid(row=9, column=2)
	scrollv = Scrollbar(frame2, orient=VERTICAL)
	scrollh = Scrollbar(frame2, orient=HORIZONTAL)
	lb = Listbox(frame2, xscrollcommand=scrollh.set, yscrollcommand=scrollv.set)
	scrollv.config(command=lb.yview)
	scrollh.config(command=lb.xview)
	scrollh.pack(side=BOTTOM, fill=X)
	scrollv.pack(side=RIGHT, fill=Y)
	title = Label(frame2, text="Previously Downloaded Lyrics").pack(side=TOP, pady=10)
	lb.pack(side=LEFT, fill=BOTH, expand=2, padx=10, pady=10)
	Files()
	win.mainloop()
def Files():
	global tracklisting
	tracklisting = []
	for file in os.listdir("C:\Lyrics"):
		tracklisting.append(os.path.join("C:\Lyrics", file))
		lb.insert(END, file)
def OpenFile():
	x = "".join(lb.curselection())
	x = int(x)
	os.startfile(tracklisting[x])
 
	
MakeWindow()

The reason for all the Filler1 etc is to fill the grid to generate gaps i could find no documented way of doing it, so that worked fine!!

Need Tkinter to run.

Any feedback or new ideas, let me know
__________________
while me is alive:
	make(life,simple)
SaturN is offline   Reply With Quote