Kurioses Problem!
Verfasst: Dienstag 8. Februar 2005, 22:37
Hab ein echt kurioses Problem! Und zwar kann ich meine Checkbuttons nicht mehr auslesen!? Es geht schon. Aber nicht innerhalb meinen Programms. Es geht immer, aber nur NICHT in meinem Programm. Warum?
Hier mal der komplette code...
Hier mal der komplette code...
Code: Alles auswählen
from Tkinter import *
from thread import start_new_thread
from whatsonair1 import *
from os import remove
from time import sleep
all=[]
for current in allparsers:
current=current()
all.append(current.__station__)
print all
print allparsers
def update_it(var, root):
while 1:
uptodate=update(read_sets())
i=0
checksum=read_sets()
for current in uptodate:
if checksum[i]==1:
var[i].set(current)
i=i+1
def update(toupdate):
i=0
result=[]
for current in allparsers:
if toupdate[i]==1:
try:
current=current()
current.feed(current.pagecontent)
result.append(current.currenttrack())
except:result.append('ERROR!')
else:
result.append(0)
i=i+1
return result
def save_settings(values, settingsroot):
try:remove('WhatsOnAir_TkSettings.ini')
except:pass
file=open('WhatsOnAir_TkSettings.ini', 'w+')
for current in values:
print current
current=current.get()
print current
file.write(current+'|#|')
file.close()
close_it(settingsroot)
def read_sets():
file=open('WhatsOnAir_TkSettings.ini', 'r')
result=file.read()
result=result.split('|#|')
stations=[]
for current in result:
if current=='':
current=0
stations.append(int(current))
return stations
def close_it(window):
window.quit()
window.destroy()
def start():
root=Tk()
root.title('SeeWhatsOnAir_Tk 0.1')
aa=0
uptodate=update(read_sets())
tracklabels=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
checksum=read_sets()
var=[StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(),
StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar()]
for current in allparsers:
if checksum[aa]==1:
current=current()
current=current.__station__
var.append(StringVar())
Label(root, text=current).place(x=4, y=20*aa)
tracklabels[aa]=Label(root, textvariable=var[aa])
var[aa].set(uptodate[aa])
tracklabels[aa].place(x=100, y=20*aa)
aa=aa+1
Button(root, text='update', command=lambda:start_new_thread(update_it, (var, root))).place(x=60, y=20*aa+20)
root.minsize(450, 20*aa+75)
root.maxsize(450, 20*aa+75)
menu = Menu(root)
root.config(menu=menu)
menu.add_command(label='New', command=settings)
root.mainloop()
def settings():
settingsroot=Tk()
settingsroot.title('Settings')
r=0
stationchecks=[]
v=[]
for current in allparsers:
current=current()
current=current.__station__
Label(settingsroot, text=current).place(x=4, y=20*r)
v.append(StringVar())
stationchecks.append(Checkbutton(settingsroot, variable=v[r]))
stationchecks[r].place(x=150, y=20*r)
stationchecks[r].select()
print v[r].get()
r=r+1
settingsroot.minsize(200, 20*r+50)
settingsroot.maxsize(200, 20*r+50)
Button(settingsroot, text="Save", command=lambda:save_settings(v, settingsroot)).place(x=50, y=(20*r)+20)
Button(settingsroot, text="Abort", command=lambda:close_it(settingsroot)).place(x=90, y=(20*r)+20)
settingsroot.mainloop()
start()