0

I am trying to get the input of what page number the user wants. They should type in a number, and click the submit button. To test it, I just want to print whatever they typed and then close the window. I've been following: http://effbot.org/tkinterbook/entry.htm as a guide, but I am stumped.

Why does

print(temp) 

not print out a number to console?

right now it prints out:

<bound method IntVar.get of <tkinter.IntVar object at 0x000001FBC85353C8>>          

I've cleaned up the code a little bit:

import sys
from file import *
from page import *
from view import View
import tkinter as tk
from tkinter import *


class ViewGui:
def __init__(self):

    #Included in the class, but unrelated to the question:
    self._file = File("yankee.txt", 25)
    self.pages = self._file.paginate()
    self.initial_list = self.pages[0].readpage(self._file.fo)
    self.initial_string = ''.join(self.initial_list)


    # Create root
    self.root = Tk()
    self.root.wm_title("yankee.txt - page 1")
    # Create frame for buttons
    self.bframe = Frame(self.root)
    self.bframe.pack(side=BOTTOM, fill=X)
    self.tbutton = tk.Button(self.bframe, text="Top", command=lambda a="top": self.clicks(a)).pack(side=LEFT, expand=1, fill=X)
    self.bbutton = tk.Button(self.bframe, text="Bottom", command=lambda a="bottom": self.clicks(a)).pack(side=LEFT, expand=1, fill=X)
    self.ubutton = tk.Button(self.bframe, text="Up", command=lambda a="up": self.clicks(a)).pack(side=LEFT, expand=1, fill=X)
    self.dbutton = tk.Button(self.bframe, text="Down", command=lambda a="down": self.clicks(a)).pack(side=LEFT, expand=1, fill=X)
    self.pbutton = tk.Button(self.bframe, text="Page", command=lambda a="page": self.pageclicks()).pack(side=LEFT, expand=1, fill=X)
    self.qbutton = tk.Button(self.bframe, text="Quit", command=quit).pack(side=LEFT, expand=1, fill=X)
    # Create and pack Text
    self.T = Text(self.root, height=35, width=60, wrap=NONE)
    self.T.pack(side=TOP, fill=X)
    # Create and pack Scrollbar
    self.S = Scrollbar(self.root, orient=HORIZONTAL, command=self.T.xview)
    self.S.pack(side=BOTTOM, fill=X)
    # Attach Text to Scrollbar
    self.T.insert('1.0', self.initial_string)
    self.T.config(xscrollcommand=self.S.set, state=DISABLED)
    self.S.config(command=self.T.xview)

def pageclicks(self):
    print("pageClicks is getting called at least...")
    pop = Tk()
    pop.wm_title("Page Number")
    pop.label = Label(pop, text="Enter a Page Number:", width=35)
    pop.label.pack(side=TOP)
    pop.entrytext = IntVar()
    Entry(pop, textvariable=pop.entrytext).pack()
    pop.submitbuttontext = StringVar()
    Button(pop, text="Submit", command=lambda a=pop: self.submitted(a)).pack(side=LEFT, pady=5, padx=40)
    pop.cancelbuttontext = StringVar()
    Button(pop, text="Cancel", command=pop.destroy).pack(side=LEFT, pady=5, padx=40)

def submitted(self, a):
    print('submitted is getting called')
    temp = (a.entrytext.get)
    print(temp)

def clicks(self, a):
    print("you clicked clicks with the " + a)
    self.root.wm_title(self._file.filename + " - Page " + self._file.buttonHandler(a))

if __name__ == "__main__":
    vg = ViewGui()
    vg.root.mainloop()
13
  • 1
    You could place your complete code since I have tried the code and I have had no problems. Commented Apr 18, 2017 at 3:16
  • added the other class, and tried to make it somewhat readable. Commented Apr 18, 2017 at 3:33
  • You could place a code that reproduces the error and can be tested Commented Apr 18, 2017 at 3:36
  • There are many issues with your code. You can not go any further with the actual design. About that pbutton: look how you implemented pageclicks() Commented Apr 18, 2017 at 4:33
  • @BillalBEGUERADJ Thank you for taking the time to look, I don't really understand your suggestions though, if you even made one. Commented Apr 18, 2017 at 4:46

2 Answers 2

2

When you create a new window you should not use Tk(), you must use tk.Toplevel()

Must change:

pop = Tk()

to

pop = tk.Toplevel()

You should also use get(), not just get. Must change:

temp = (a.entrytext.get)

to

temp = a.entrytext.get()

Code:

def pageclicks(self):
        print("pageClicks is getting called at least...")
        pop = tk.Toplevel()
        pop.wm_title("Page Number")
        pop.label = Label(pop, text="Enter a Page Number:", width=35)
        pop.label.pack(side=TOP)
        pop.entrytext = IntVar()
        Entry(pop, textvariable=pop.entrytext).pack()
        pop.submitbuttontext = StringVar()
        Button(pop, text="Submit", command=lambda a=pop: self.submitted(a)).pack(side=LEFT, pady=5, padx=40)
        pop.cancelbuttontext = StringVar()
        Button(pop, text="Cancel", command=pop.destroy).pack(side=LEFT, pady=5, padx=40)

def submitted(self, a):
    print('submitted is getting called')
    temp = a.entrytext.get()
    print(temp)
Sign up to request clarification or add additional context in comments.

1 Comment

wowzers what a doozey. thanks for sticking this one out. the code you posted is working for me. It was that get() that was the problem.
0

Made changes to these two methods and now it is working.

def pageclicks(self):
    print("pageClicks is getting called at least...")
    pop = Tk()
    pop.wm_title("Page Number")
    pop.label = Label(pop, text="Enter a Page Number:", width=35)
    pop.label.pack(side=TOP)
    pop._entry = Entry(pop)
    pop._entry.pack()
    pop._entry.focus_set()
    Button(pop, text="Submit", command=lambda a=pop: self.submitted(a)).pack(side=LEFT, pady=5, padx=40)
    Button(pop, text="Cancel", command=pop.destroy).pack(side=LEFT, pady=5, padx=40)

def submitted(self, _pop):
    temp = _pop._entry.get()
    print(temp)
    _pop.destroy()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.