Jul-24-2019, 09:25 AM
Hi again,
i am trying a simple gui, 2 buttons with an image as icon, in this exaple (banane, melone)...
if i press one of the button, the text will be displayed..
it is almost working, however the image icons are tooo big (zoomed out)...what should i do, so that the images fit into the buttons..
i tried the following, it didn't work (i just learned about events yesterday)
i am trying a simple gui, 2 buttons with an image as icon, in this exaple (banane, melone)...
if i press one of the button, the text will be displayed..
it is almost working, however the image icons are tooo big (zoomed out)...what should i do, so that the images fit into the buttons..
class Fruit: def __init__(self): self.root = Tk() self.banane = PhotoImage(file="banane.jpg") self.melone = PhotoImage(file="melone.jpg") self.b1 = Button(self.root,image=self.banane,width="30",height="30", command=self.updatebanane).pack(side=LEFT) self.b2 = Button(self.root,image=self.melone,width="30",height="30", command=self.updatemelone).pack(side=LEFT) self.label = Label(self.root, font=('Arial', 14), width=20) self.label.pack(side=RIGHT) self.root.mainloop() def updatebanane(self): self.label.config(text='Banane') def updatemelone(self): self.label.config(text='Melone') f = Fruit()2. Question... is there a way to use events so that i need only one method to update the text instead of 2 ?
i tried the following, it didn't work (i just learned about events yesterday)
self.b1 = Button(self.root,image=self.banane,width="30",height="30", command=self.update).pack(side=LEFT) self.b2 = Button(self.root,image=self.melone,width="30",height="30", command=self.update).pack(side=LEFT) . . . def update(self, event): if event.widget = self.b1 self.label.config(text='Banane') if event.widget = self.b2 self.label.config(text='Melone')But i get the following error
Error:TypeError: update() missing 1 required positional argument: 'event'