Dec-28-2018, 08:48 AM
Hi Guys,
I'm new in the python coding scene and began learning Tkinter yesterday. I wrote a little dice rolling programm, based on a tkinter tutorial series(https://pythonprogramming.net/python-3-t...-tutorial/).
I know it's not the most intelligent program you can write, but I just want to learn.
The pictures are in my google drive folder(https://drive.google.com/open?id=1jrdAb3...NjAuO77tJO).
But my main problem is that it does only show the pictures((https://drive.google.com/open?id=1jrdAb3...NjAuO77tJO)) once, after you click the button. What do I have to change?
Thank you,
tomX
I'm new in the python coding scene and began learning Tkinter yesterday. I wrote a little dice rolling programm, based on a tkinter tutorial series(https://pythonprogramming.net/python-3-t...-tutorial/).
I know it's not the most intelligent program you can write, but I just want to learn.
from tkinter import * from random import randint from PIL import Image, ImageTk class Window(Frame): def __init__(self, master = None): Frame.__init__(self, master) self.master = master self.init_window() def init_window(self): self.master.title("Rolling the dice") self.pack(fill=BOTH, expand=1) #quitButton = Button(self, text= "quit", command=self.client_exit) #quitButton.place(x=0, y=0) #making the roll button rollButton = Button(self, text= "Roll the dice", command = self.roll()) rollButton.place(x = 180, y = 270) #making the menu menu = Menu(self.master) self.master.config(menu=menu) #making the file cascade in menu with button exit file = Menu(menu) file.add_command(label="Exit", command=self.client_exit) menu.add_cascade(label="File", menu=file) edit = Menu(menu) edit.add_command(label="Undo") edit.add_command(label="Roll the dice", command=self.roll()) menu.add_cascade(label= "Edit", menu=edit) def roll(self): randomNumber = randint(1, 6) if randomNumber == 1: load = Image.open("dices_1.png") render = ImageTk.PhotoImage(load) img = Label(self, textvariable=randomNumber) img.image = render img.place(x=0, y=0) elif randomNumber == 2: load = Image.open("dices_2.png") render = ImageTk.PhotoImage(load) img = Label(self, image=render) img.image = render img.place(x=0, y=0) elif randomNumber == 3: load = Image.open("dices_3.png") render = ImageTk.PhotoImage(load) img = Label(self, image=render) img.image = render img.place(x=0, y=0) elif randomNumber == 4: load = Image.open("dices_4.png") render = ImageTk.PhotoImage(load) img = Label(self, image=render) img.image = render img.place(x=0, y=0) elif randomNumber == 5: load = Image.open("dices_5.png") render = ImageTk.PhotoImage(load) img = Label(self, image=render) img.image = render img.place(x=0, y=0) elif randomNumber == 6: load = Image.open("dices_6.png") render = ImageTk.PhotoImage(load) img = Label(self, image=render) img.image = render img.place(x=0, y=0) def client_exit(self): exit() root = Tk() root.geometry("400x300") app = Window(root) root.mainloopFirst I want to ask some feedback about the structure of the code. Is it as bad as I think it is?
The pictures are in my google drive folder(https://drive.google.com/open?id=1jrdAb3...NjAuO77tJO).
But my main problem is that it does only show the pictures((https://drive.google.com/open?id=1jrdAb3...NjAuO77tJO)) once, after you click the button. What do I have to change?
Thank you,
tomX