Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 777831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:40:15+00:00 2026-05-14T19:40:15+00:00

Im new to GUI programming, and haven’t done much OOP. Im working on a

  • 0

Im new to GUI programming, and haven’t done much OOP. Im working on a basic calculator app to help me learn GUI design and to brush up on OOP. I understand that anything GUI related should be kept seperate from the logic, but Im unsure how to implement interaction between logic an GUI classes when needed i.e. basically passing variables back and forth…

Im using TKinter and when I pass a tkinter variable to my logic it only seems to hold the string PY_VAR0.

def on_equal_btn_click(self):
            self.entryVariable.set(self.entryVariable.get() + "=")
            calculator = Calc(self.entryVariable)
            self.entryVariable.set(calculator.calculate())

Im sure that im probably doing something fundamentally wrong and probabaly really stupid, I spent a considerable amount of time experimenting (and searching for answers online) but Im getting no where. Any help would be appreciated.

Thanks,
V

The Full Program (well just enough to show the structure..)

import Tkinter

class Gui(Tkinter.Tk):
    def __init__(self,parent):
        Tkinter.Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()

    def initialize(self):
        self.grid()
        self.create_widgets()
        """ grid config """
        #self.grid_columnconfigure(0,weight=1,pad=0)
        self.resizable(False, False)

    def create_widgets(self):

        """row 0 of grid"""

        """Create Text Entry Box"""
        self.entryVariable = Tkinter.StringVar()
        self.entry = Tkinter.Entry(self,width=30,textvariable=self.entryVariable)
        self.entry.grid(column=0,row=0, columnspan = 3 )
        self.entry.bind("<Return>", self.on_press_enter)

        """create equal button"""
        equal_btn = Tkinter.Button(self,text="=",width=4,command=self.on_equal_btn_click)
        equal_btn.grid(column=3, row=0)

        """row 1 of grid"""

        """create number 1 button"""
        number1_btn = Tkinter.Button(self,text="1",width=8,command=self.on_number1_btn_click)
        number1_btn.grid(column=0, row=1)

    def on_equal_btn_click(self):
        self.entryVariable.set(self.entryVariable.get() + "=")
        calculator = Calc(self.entryVariable.get())
        self.entryVariable.set(calculator.calculate())

class Calc():

    def __init__(self, equation):
        self.equation = equation

    def calculate(self):
        #TODO: parse string and calculate...
        return self.equation 

# define undefined functions for sufficiently liberal meanings of "define"
Gui.on_press_enter = Gui.on_equal_btn_click
Gui.on_number1_button_click = Gui.on_equal_btn_click

if __name__ == "__main__":
    app = Gui(None)
    app.title('Calculator')
    app.mainloop()   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:40:16+00:00Added an answer on May 14, 2026 at 7:40 pm

    Corrected:

    My first answer was totally mistaken, ignore it. The problem was that you were accidentally overwriting your entry variable text with an a string representation of the entryVariable object. Note the addition of a get() in the call to Calc():

    def on_equal_btn_click(self):
        print self.entryVariable.get()
        self.entryVariable.set(self.entryVariable.get() + "=")
        print self.entryVariable.get()
        calculator = Calc(self.entryVariable.get())
        self.entryVariable.set(calculator.calculate())
    

    welcome to weakly typed languages, that sort of bug can drive you up a wall. I find liberal use of print and repr() (or print('foo %r' % object)) to be invaluable in such times.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to GUI programming and need a little help with a list
I'm new to GUI programming, but need to create a multiple window GUI. Does
After reading Jeff's blog post and being fairly new to GUI programming, I'm wondering
I'm new to Python and am starting to teach myself GUI programming (hopefully) using
I've recently began working through a C++ Gui Programming with Qt 4 book. However,
I'm new GUI and programming as whole and so far I have a general
First off, a lil about me, i'm very new to GUI programming, especially with
Ok, i'm new to the whole GUI programming so this might be a very
I am working on an assignment for my GUI programming class, in which we
I am really new to GUI programming in Java, I did a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.