Jun-22-2017, 10:07 PM
I tried to make a program which says: "Press the button to throw the dices" and when you press the button it shows 2 random dice images. But it does not show pics eventhough the form application gets bigger when I press the button which means it takes pictures but don't show them (I think) Does anyone know how to fix this problem?
Also when I click the button for second time I want delete old images and create new two random dice images. How can I do that?
Thanks for all your help :)
Also when I click the button for second time I want delete old images and create new two random dice images. How can I do that?
Thanks for all your help :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
from tkinter import * import random root = Tk() topframe = Frame(root) topframe.pack(side = TOP) bottomframe = Frame(root) bottomframe.pack(side = BOTTOM) def selecter(): randomNumber = random.randrange( 1 , 666 ) if randomNumber < 111 : zar1 = PhotoImage( file = r 'C:\Users\aliyu_000\Desktop\zarlar\1.png' ) zar1label = Label(bottomframe, image = zar1) zar1label.pack(side = LEFT) elif randomNumber < 222 : zar2 = PhotoImage( file = r 'C:\Users\aliyu_000\Desktop\zarlar\2.png' ) zar2label = Label(bottomframe, image = zar2) zar2label.pack(side = LEFT) elif randomNumber < 333 : zar3 = PhotoImage( file = r 'C:\Users\aliyu_000\Desktop\zarlar\3.png' ) zar3label = Label(bottomframe, image = zar3) zar3label.pack(side = LEFT) elif randomNumber < 444 : zar4 = PhotoImage( file = r 'C:\Users\aliyu_000\Desktop\zarlar\4.png' ) zar4label = Label(bottomframe, image = zar4) zar4label.pack(side = LEFT) elif randomNumber < 555 : zar5 = PhotoImage( file = r 'C:\Users\aliyu_000\Desktop\zarlar\5.png' ) zar5label = Label(bottomframe, image = zar5) zar5label.pack(side = LEFT) else : zar6 = PhotoImage( file = r 'C:\Users\aliyu_000\Desktop\zarlar\6.png' ) zar6label = Label(bottomframe, image = zar6) zar6label.pack(side = LEFT) def selecter2x(): selecter() selecter() infozarat = Label(topframe, text = "Zar atmak için butona basın:" ) infozarat.pack(side = LEFT) zarat = Button(topframe, text = ' Zar AT ' , bg = "black" , fg = "white" , command = selecter2x) zarat.pack(side = LEFT) root.mainloop() |