I have converted a paper boardgame into a program as my first project using Python and Tkinter. When the game is over, there are four text boxes into which the player can enter their scores. There is also a fith text box into which they can enter how many points they have lost for skipping turns.
What I am trying to get to work is when the user has entered all these numbers in the appropriate boxes, they can click on a button titled “Calculate”, and the sum of the four scores, minus the points for skiping turns, will be displayed in a label, or another textbox.
I’m very new to programing and I’m struggling to get this to work.
I’ve attched a picture of the programn to help with understanding what I’m trying to do.The game, note the score boxes at the bottom](https://i.sstatic.net/wjmcPlQY.png)
I have been practising outside my actual game programn trying to add the user entered numbers in two entry boxes together, but it hasn’t worked. I know what I want the code to do in plain english: “Take all these integer varaibles that the user enters in these textboxes, perform the calculation, and display the result here.” However, I dont have the knowledge of Python syntax to acheive this. And I couldn’t find anything online.
I will include my practise code, but please note I know this code is probally very wrong, and it obviousy doesn’t work. But hopfully it will help illustrate what I’m trying to do. Thank you in advance.
import tkinter
class MyGui:
def __init__(self):
self.window = tkinter.Tk()
self.e1 = tkinter.Entry(self.window)
self.e1.pack(fill='x')
self.e2 = tkinter.Entry(self.window)
self.e2.pack(fill='x')
self.label = tkinter.Label(self.window)
self.label.pack(fill='x')
self.button1 = tkinter.Button(self.window, text="add", font=('Arial', 16), command=self.add)
self.button1.pack()
self.window.mainloop()
def add(self):
entry1 = self.e1.get
entry1 = int(entry1)
entry2 = self.e2.get
entry2 = int(entry2)
self.label = entry1 + entry2
MyGui()
Tom Newing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.