Advertisement
Guest User

Untitled

a guest
Feb 7th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. from functools import partial
  2. from random import randint, randrange
  3. from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLineEdit
  4.  
  5.  
  6. class MainWidget(QWidget):
  7.     def __init__(self):
  8.         super(MainWidget, self).__init__()
  9.         self.buttonDict = {"High-Low-Good-Bad": "hlgb"}
  10.         self.inputDict = {"display1": "", "display2": ""}
  11.         self.vertCol = QVBoxLayout(self)
  12.  
  13.         for val, key in self.inputDict.items():
  14.             self.inputs = QLineEdit(key, self)
  15.             self.inputs.setText(key)
  16.             print("Key - " + key)
  17.             print("Val - " + val)
  18.             self.vertCol.addWidget(self.inputs)
  19.  
  20.         for key, val in self.buttonDict.items():
  21.             self.buttons = QPushButton(key, self)
  22.             self.buttons.setToolTip("D20 die rolled: 1-10=low, 11-20=high; Coin Flip: 0=Heads(Good) 1=Tails(Bad)")
  23.             self.buttons.clicked.connect(partial(self.handlehlgb))
  24.             #self.buttons.clicked.connect(self.inputs.update())
  25.             self.vertCol.addWidget(self.buttons)
  26.  
  27.     def handlehlgb(self):
  28.         self.coinFlip = randrange(2)
  29.         self.rollD20 = randint(1, 20)
  30.         if self.coinFlip <= 0:
  31.             self.inputDict.update({'display1': 'Good'})
  32.             print(self.inputDict["display1"])
  33.         else:
  34.             self.inputDict.update({'display2': 'Bad'})
  35.             print(self.inputDict["display2"])
  36.         if self.rollD20 <= 10:
  37.             self.inputDict.update({'display2': 'Low'})
  38.             print(self.inputDict["display2"])
  39.         else:
  40.             self.inputDict.update({'display2': 'High'})
  41.             print(self.inputDict["display2"])
  42.  
  43. if __name__ == "__main__":
  44.     app = QApplication()
  45.     w = MainWidget()
  46.     w.show()
  47.     app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement