[Tutor] newbie help..image in toplevelwindow?
a.dijkstra03@kpn.com
a.dijkstra03@kpn.com
Tue, 12 Jun 2001 11:22:36 +0200
Hi there,
This is one of my first attempts building a application with Tkinter.
Could anyone explain to me what i'm doing wrong? I'm trying to insert a
image in the toplevel window. I'm using win NT and python2.1.
Thanks in advance
regards Arjen
from Tkinter import *
from whrandom import choice
from string import upper
from re import sub
kleur=['red', 'yellow', 'brown', 'green', 'purple', 'black', 'orange',
'white',
'blue']
alist=[]
klos='.....\n moet koffie halen!!!'
best=open('koffielijst', 'r')
x=best.readlines()
for item in x:
a=sub('\n', '', item)
alist.append(a)
best.close()
def kiezen():
kl=choice(kleur)
klos=upper(choice(alist)) + '\n moet koffie halen!!!'
label.configure(text=klos, fg=kl)
def nieuw():
invoer=entry.get()
if invoer != '':
alist.append(invoer)
toev=open('koffielijst', 'a')
toev.write(invoer + '\n')
toev.close()
lijst.insert(END, invoer)
entry.delete(0, END)
return alist
def opslaan():
opsl=open('koffielijst', 'w')
for item in alist:
opsl.write(item + '\n')
opsl.close()
def deleteButtonClick():
indicies = lijst.curselection()
indicies = [int(index) for index in indicies] # Cast indicies to ints
indicies.sort()
indicies.reverse()
for index in indicies:
lijst.delete(index)
alist.pop(index)
opslaan()
return alist
def newwin():
wat=Toplevel()
fr=Frame(wat)
t=Label(fr, text='Versie 1.0', fg='red', bg='white')
t.pack(pady=10)
filename='PythonPoweredSmall.gif'
img = PhotoImage(file=filename)
hm = Label(fr, image=img)
hm.pack()
wat.title('info')
fr.pack()
top=Tk()
label=Label(top, text=klos, font='Times 30 bold', fg='black')
label.pack()
menubar = Menu(top)
filemenu=Menu(menubar, tearoff=0)
filemenu.add_command(label="?????", command=newwin)
top.config(menu=menubar)
menubar.add_cascade(label="informatie", menu=filemenu)
frame=Frame(top, bd=20, relief=SUNKEN)
frame.pack(side=LEFT)
entry=Entry(frame, width=23)
entry.pack()
frame1=Frame(frame)
frame1.pack(fill=X)
knop=Button(frame1, text='toevoegen', command=nieuw)
knop.pack(side=LEFT)
deleteButton = Button(frame1, text='verwijderen', command=deleteButtonClick)
deleteButton.pack(fill=X)
scrollbar=Scrollbar(frame)
scrollbar.pack(side=RIGHT, fill=Y)
lijst=Listbox(frame, height=5, width=20, yscrollcommand=scrollbar.set)
for item in alist:
lijst.insert(END, item)
lijst.pack(side=BOTTOM)
scrollbar.config(command=lijst.yview)
Kies=Button(top, text='kiezen', font='Times 15', command=kiezen)
##Kies.bind('<Key-Return>')
Kies.pack(fill=X)
quit=Button(top, text='afsluiten', font='Times 15', command=top.quit)
quit.pack(fill=X)
#filename='PythonPowered.gif'
#img = PhotoImage(file=filename)
#hm=Label(top, image=img)
#hm.pack(pady=30)
filename1='koffie.gif'
img1 = PhotoImage(file=filename1)
hm1=Label(top, image=img1)
hm1.pack(pady=18)
top.title(' KOFFIEMACHINE')
mainloop()