Hello all, just making a quick check to see if anyone can help me fix my code. I need to show the result in an entry screen...

# Tkinter class template to test apps

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

class MyApp(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.title("Tkinter basic class")
        # use width x height + x_offset + y_offset (no spaces!)
        self.geometry("300x150+50+50")
        self['bg'] = 'green'
        self.createEight()

    def createEight(self):
        top=self.winfo_toplevel()
        top.rowconfigure(0, weight=1)
        top.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
        self.button8 = tk.Button(self, text="    8    ",
            font=("Arial", 12), bg="white", fg="blue",
            cursor="crosshair", command=lambda: self.click('8'))
        self.button8.grid(row=2, column=1, sticky='nesw')
        
    def click(self, val):
        s = "Button " + val + " clicked"
        # show result in title
        self.title(s)


app = MyApp()
app.mainloop()

I've tried everything and it gives me all types of errors. Any help will be good. :)

I do not get any errors when running the code, could you include erron messages, input then, expected output and what you did to spot the problem (printing to spot the place of problem)

I've tried everything and it gives me all types of errors.

It worked find for me. I clicked button 8 and it displayed "button 8 clicked", so you'll have to include the error message(s) for any further help.

oh sorry i meant to say that i want to change it so that when i click on the eight button it shows the number eight in an Entry Screen.

Somthing like this?

def click(self, val):
        s = "Button %s was clicked" % val
        label = tk.Label(text = s, width = 15)
        label.grid(row = 0, column = 0)        
        s = "Button " + val + " clicked"        
        # show result in title
        self.title(s)

You really don't want to create a new label every time you click.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.