![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
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) |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
First obvious crit - don't use Tkinter. It's inherently flawed and very slow (apparently its bound to Python via tcl, so two layers of interpreted language). Use a real GUI toolkit like wxPython or PyQt. Tkinter's many flaws can be found by Googling for it. Tkinter apps look horrifically ugly under Linux too.
Secondly - Don't hardcode paths like "C:\Lyrics" - there is no 'C:\' for me here, so I had to manually change everything to have a go. Thirdly - More feedback. I entered my artist and song-name ("Smashing Pumpkins", "Cherry"), and then pressed Search. Nothing happened. I pressed Open Chosen File.. still nothing, except looking at Konsole showed me that you've got a bug for each. Here's the trackback: Pressing "Search": Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1345, in __call__
return self.func(*args)
File "tkintergui.py", line 23, in Search
os.startfile("%s\%s.html"% (path, "%s by %s"% (tracks, artists)))
AttributeError: 'module' object has no attribute 'startfile'Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1345, in __call__
return self.func(*args)
File "tkintergui.py", line 77, in OpenFile
x = int(x)
ValueError: invalid literal for int(): |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
It works fine for me!!
I have the same python version, i've just run the exact same search as you now, and it's fine!! Also, i have wxPython, but i can't find a decent on-line tutorial! lol So if you've got a link or anything that would be good. And thanks for the note about paths! Never really thought about that. Thanks ![]()
__________________
while me is alive: make(life,simple) |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
There are plenty of good wxPython tutorials. Try working through this
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
Thanks, I'll see what wonders this brings
![]() Thanks for your input ![]()
__________________
while me is alive: make(life,simple) |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Jul 2005
Location: Philadelphia, PA
Posts: 11
Rep Power: 0
![]() |
I agree with Cerulean, Tkinter is terrible. wxPython IMO is the best I have used. The homepage has semi-good tutorials, then I would suggest just looking at other people's code to get better ideas of how to do things. I was able to code a nice looking GUI in about 10 hours total.
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
Tkinter seems ok for small little apps like that!! i may be wrong!! But, like i say seems ok, I'll probably look in to using wxPython for larger scale projects, but atm it seems to suit ok,
and it's easy to use hehe
__________________
while me is alive: make(life,simple) |
|
|
|
|
|
#8 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
I find wxPython easier to use. Use wxPython for a little and you'll see that it is too. It seems like a hassle, learning something new after you just learnt a bit of Tkinter, but let me just re-phrase why Tkinter is bad:
1. Slow. Tkinter goes through an extra layer of interperation (it wraps tcl/tk), while wxPython is directly bound to wxWidgets (which is written in C++). 2. Applications look ugly and don't integrate with the rest of the Linux desktop (it doesn't use GTK or Qt). I can send you a screenshot if that would help you realise the true vulgarness of the Tkinter GUI. 3. Lack of high-level abstraction. Tkinter is a pretty low level, so you're touching the guts far too often. That really does make it harder to use. |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
ok,
I'll switch to wxPython straight away! hehe, Thanks for the tips..You live and learn, trail and error and all that palava, thanks ![]()
__________________
while me is alive: make(life,simple) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|