TM3 – Scientific Computing Lab

Nama : Ryo Hadinata
NIM    : 1601250023
04PAW

IT-Math
Bina Nusantara University

from msdie import MSDie
from graphics import GraphWin, Point, Text
from button import Button
from dieview import DieView

def main():
 win = GraphWin("Penjumlahan Dadu")
 win.setBackground("pink")
 win.setCoords(0,0,100,100)
 

 dice1 = DieView(win, Point(30,70), 20)
 dice2 = DieView(win, Point(70,70), 20)
 rollBttn = Button(win, Point(50,45), 60, 10, "Acak Dadu")
 rollBttn.activate()
 quitBttn = Button(win, Point(50,10), 20, 10, "Quit")
 
 mouseclick = win.getMouse()
 text = Text(Point(50,25), "")
 while not quitBttn.clicked(mouseclick):
  if rollBttn.clicked(mouseclick):
   text.setText("")
   value1 = MSDie(6)
   value1.roll()
   dice1.setValue(value1.getValue())
   nilai1 = int(value1.getValue())
   value2 = MSDie(6)
   value2.roll()
   dice2.setValue(value2.getValue())
   nilai2 = int(value2.getValue())
   total = nilai1 + nilai2
   text.setText("Jumlah angka pada dadu: %d" % total)
   text.draw(win)
   quitBttn.activate()
  mouseclick = win.getMouse()
  text.undraw()

 win.close()

main()

Untitled-1 copy

Click here to download code (*.py)

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *