5/6/2023 0 Comments Coin flip generator![]() ![]() ![]() #Begins the execution of the QApplication #Processes the second change to the QLabel 'dice' #Sets the image inside the QLabel 'coin' to a random coin image (head or tail) into the QLabel 'coin' #Pauses the execution of any more code for 0.5 seconds #Processes any change made to the program/window in this case the change of the image in the Qlabel 'coin' (QPixmap('coin_flipping_animation.png').scaled(162, 302, Qt.KeepAspectRatio, Qt.FastTransformation)) #Sets the image inside the Qlabel 'coin' to a coin flipping animation.aspect ratio is ignored to get the animation to fit inside the window correctly #Sets the window icon to the image file 'icon.png' located in the same folder as the source file #Locks the size of the window and make it impossible for the user to change it #Sets where on the screen the window will open and the size of the window respectively using x and y coordinates #Connects the QPushButton 'btn' to the function 'flipcoin' to activate when the button is clicked #Selects the font/font size for the QToolTip above on the QPushButton 'btn' using QFont #Creates a tooltip when user hovers over the QPushButton 'btn' using QToolTip #Selects the font/font size for the label on the QPushButton 'btn' using QFont #Creates the button that will activate the simulated coin flip when clicked and labels it 'Flip' using QPushButton ![]() (QPixmap('coin_' + str(randint(1, 2)) + '.png').scaled(162, 302, Qt.KeepAspectRatio, Qt.FastTransformation)) #Uses QPixmap to place a random coin image (head or tail) into the QLabel 'coin' #Creates the QLabel 'coin' which will contain the image of the coin #Creates the main widget which will contain everything else From PyQt5.QtWidgets import (QToolTip, QPushButton, QApplication, QWidget, QLabel)įrom PyQt5.QtGui import (QIcon, QPixmap, QFont) ![]()
0 Comments
Leave a Reply. |