Connecting the GUI application with the smart contract
Since the script is already an ape
script, you can connect to the smart contract directly. There are three smart contract functions that this voting GUI application needs. They are the functions to get the number of proposals, read the proposal names, and vote for a proposal.
Right now, you hardcoded the proposals inside the combo box. But you want to get them from the smart contract.
Edit voting_gui_app.py
; locate this line:
self.combobox.addItems(["---", "beach", "mountain"])
Change it to this line:
self.combobox.addItems(["---"])
You don’t want to hardcode the options on the combo box anymore.
Then, you replace all the code inside the main
function with the following code:
def main(): voting_app_address = os.environ["VOTING_APP_ADDRESS"] contract = project.VotingApp.at(voting_app_address) ...