0

I have a function that print the results of scoreboard game in terminal (see the picture below). I want to modify the function in a way to print the result on GUI interface using python -tkinter or other technique. I don't have any experince in GUI with python. Can some one help me?

Here is the function that print the scoreboard result after the user enter the score in the terminal for the corresponding frame:

 def print_scoreboard(self):
        print()
        print("Scoreboard")

        # print heading
        print("----------------------------------------------------------------------------")
        heading = self.fixed_width("Frames") + "|"
        for frame in self.frames:
            heading = heading + self.fixed_width(str(frame), 5) + "|"
        print(heading)
        print("----------------------------------------------------------------------------")

        # print results
        for player in self.players:
            results = ''
            for frame, res in player.results.items():
                results = results + self.fixed_width(res['roll_1'] + " " + res['roll_2'] + " " + res['roll_3'], 5) + "|"

            print(self.fixed_width(player.name) + "|" + results)

            scores = ''
            for frame, s in player.scores.items():
                scores = scores + self.fixed_width(str(s['frame_score']), 5) + "|"

            print(self.fixed_width("Frame Scores") + "|" + scores)

            totals = ''
            for frame, s in player.scores.items():
                totals = totals + self.fixed_width(str(s['running_total']), 5) + "|"

            print(self.fixed_width("Running Total") + "|" + totals)
            print("----------------------------------------------------------------------------")

        print()

After i did some research, i got with the following example in python - tkinter. This example takes a variable value as input and display it in a gui window:

from tkinter import *
import tkinter
from tkinter import messagebox
number = 0

# object of tkinter
# and background set for light grey
master = Tk()
master.configure(bg='light grey')
master.title("Programme")
master.geometry('500x650')

# Variable Classes in tkinter
score = StringVar();
# Creating label for each information
# name using widget Label
label = Label(master, text="The total score is :" + str(number) ,font=("Arial", 25) ,bg = "light grey").grid(row=2, sticky=W)
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable= score ,bg = "light grey").grid(row=2,column=1, sticky=W)
StringVar(master=master)
master.mainloop()

To make it clear, in the following image you find a producable example in terminal. I want to display the same content of this image (terminal) in GUI interface enter image description here

talal
  • 1
  • 1
  • First of all why do you have a `StringVar(master=master)` just sitting there. It isn't doing anything. Also instead of a `textvariable` it's easier to just pass in the text string like this: `Label(master, text="Hello world\nThis is one a new line")` – TheLizzard Apr 27 '21 at 17:52
  • 1
    Also when you do: `label = Label(...).grid(...)`, the variable `label` is always `None`. For more info read [this](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) – TheLizzard Apr 27 '21 at 17:54
  • Also also there are quite a few ways of doing what you need. I suggest looking into [`ttk.Treeview`](https://docs.python.org/3/library/tkinter.ttk.html#tkinter.ttk.Treeview) – TheLizzard Apr 27 '21 at 17:56
  • You can use `ttk.Treeview`. Take a look at [something similar](https://github.com/nihaalnz/TypeTestColor/blob/3485ae144c5ad450da6fdda20277b04ef08b04c3/color_game.py#L95) I made with scorecard – Delrius Euphoria Apr 27 '21 at 18:12

0 Answers0