0

I'm writing a program to keep the score of a 14-1 billiard(pool) match. Since I needed multiple windows I used tkinter frames. The frames for 2 pages work with out difficulty. My problem is entering data. The first item to be entered in each players name. Both text boxes appear on the screen, and data can be entered. If I try to display the data after entering it I get nothing. I have been working on this for days. And I sure someone can look at it, and say hey knuckle head you did do this right. Would appropriate some help.

import tkinter as tk
from tkinter import *


TITLE_FONT = ("Helvetica", 18, "bold")
TITLE_FONT_LINE2 = ("Helvetica", 14, "bold")

class SampleApp(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        # the container is where we'll stack a bunch of frames
        # on top of each other, then the one we want visible
        # will be raised above the others

        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in (StartPage, PageOne, PageTwo):
            page_name = F.__name__
            frame = F(parent=container, controller=self)
            self.frames[page_name] = frame

            # put all of the pages in the same location;
            # the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame("StartPage")

    def show_frame(self, page_name):
        '''Show a frame for the given page name'''
        frame = self.frames[page_name]
        frame.tkraise()


class StartPage(tk.Frame):

    def __init__(self, parent, controller):

        player1 = StringVar()
        player2 = StringVar()
        game_balls = IntVar()


        tk.Frame.__init__(self, parent)
        self.controller = controller
        self.configure(background='green')
        self.controller.title('Billard Score Keeping')  
        label1 = tk.Label(self,text="This Program is for Scoring 14-1 Straight Pool", font=TITLE_FONT, bg = 'green')
        label1.pack()
        label = tk.Label(self, text="Championship 14-1 Match is 150 Balls", font=TITLE_FONT_LINE2, bg = 'green')
        label.pack()
        label2 = tk.Label(self,text="Player One Name ", font=TITLE_FONT_LINE2, bg = 'green').place(x=45,y=70)
        label3 = tk.Label(self,text='Player Two Name', font=TITLE_FONT_LINE2, bg = 'green').place(x=445,y=70)
        label4 = tk.Label(self,text='Enter Number of Balls in Match', font=TITLE_FONT_LINE2, bg = 'green').place(x=185,y=110)

        # Here is where I'm Having difficulty:

        self.entry = tk.Entry(self, text=player1, width=7, font=TITLE_FONT_LINE2).place(x=60,y=100)
        self.entry = tk.Entry(self,text=player2, width=7, font=TITLE_FONT_LINE2).place(x=480,y=100)
        self.entry = tk.Entry(self,text=game_balls, width=4, font=TITLE_FONT_LINE2).place(x=275,y=140)

        button1 = tk.Button(self, text="Go to Page One",
                            command=lambda: controller.show_frame("PageOne"))

        button2 = tk.Button(self, text="Go to Page Two",
                            command=lambda: controller.show_frame("PageTwo"))
        button1.place(x=275,y=440)
        button2.place(x=275,y=540)


class PageOne(tk.Frame):


    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        self.controller.geometry('615x615+415+190')
        label = tk.Label(self, text="This is page 1", font=TITLE_FONT)
        label.pack(side="top", fill="x", pady=10)




        button = tk.Button(self, text="Go to the start page",
                           command=lambda: controller.show_frame("StartPage"))
        button.pack()


class PageTwo(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        label = tk.Label(self, text="This is page 2", font=TITLE_FONT)
        label.pack(side="top", fill="x", pady=10)
        button = tk.Button(self, text="Go to the start page",
                           command=lambda: controller.show_frame("StartPage"))
        button.pack()


if __name__ == "__main__":

    app = SampleApp()
    app.mainloop()
Jacob Vlijm
  • 3,099
  • 1
  • 21
  • 37

2 Answers2

0

I can't see any attempt to access the contents of the text entry widgets. As such your code does exactly what I'd expect it to do.

If you want to read the contents of a text entry widget you should create a StringVar to hold the contents

self.playerone = StringVar()
self.entry1 = ttk.Entry(parent, textvariable=playerone)

The content of the entry can then be read from the content of the playerone variable for example playeronename = self.playerone.get() (Of course the variable must use the fully qualified name with the namespace)

There is documenation on the entry widget at http://www.tkdocs.com/tutorial/widgets.html#entry and http://effbot.org/tkinterbook/entry.htm

James K
  • 3,692
  • 1
  • 28
  • 36
-1

Your code and your post is so messy. About your problem: I refer you to use GET method, from each entry box take data with using GET method, next ascribe it into a variable, it's simplest way to take a data from entry box. In applications like yours, I make button near entry box, and in command attribute I do something like this

bttn = Button(self, text='enter', command=self.txt_box.get(0, END))
dannyxn
  • 422
  • 4
  • 16
  • 1
    The method isn't GET, it's `get`. Case is important, especially when helping beginners. Plus, your command will run when the button on s defined instead of when it is clicked. – Bryan Oakley Sep 03 '16 at 19:17