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

  • Home
  • SEARCH
  • 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 8666099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:38:44+00:00 2026-06-12T17:38:44+00:00

The below code is supposed to throw up the specified tkMessagebox when the button

  • 0

The below code is supposed to throw up the specified tkMessagebox when the button is pressed (eg. if update_cost button is pressed before an item is selected, it will throw up an error. HOWEVER, it is currently only showing up after I press the OK button after pressing the update_cost.

Can anyone see what i’ve done wrong? Cheers. (Code sample below).

def update_name(self, new_name):
    key=self.get_key_from_selection()  
    if key == None:  
        tkMessageBox.showerror("Update Name","No item selected.")
    else:  
        self.products.get_item(key).set_name(new_name)  
        self.refresh_listbox()


def update_cost(self, new_cost):  
    key=self.get_key_from_selection()  
    if key!=None:  
        item=self.products.get_item(key)  
        if item.get_type()==PART:  
            if new_cost.isdigit():  
                item.set_cost(int(new_cost))  
                self.refresh_listbox()  
            else:  
                tkMessageBox.showerror("Update Cost","Your input should be a number.")  
        else:  
            tkMessageBox.showerror("Update Cost","Action: 'Update_Cost' cannot be performed on a compound item.")  
    else:  
        tkMessageBox.showerror("Update Cost","No item selected.")  

def update_items(self, new_items_list):  
    key=self.get_key_from_selection()  
    if key!=None:  
        item=self.products.get_item(key)  
        if item.get_type()==COMPOUND:  
            # In order to use the internal methods of compound class to check the format and dependence, a temporary compound will recieve new list first before add to the products list..  
            temp=Compound('temp','',self.products,[])  
            try:  
                temp.set_items(new_items_list)  
            except:  
                tkMessageBox.showerror("Update Items","Invalid Items List.")  
                return  
            do=True  
            # Check all the items in the new list to ensure them not conflict any conditions below, or the add operation will not be done.  
            for sub_item in temp.get_depend():  
                if sub_item not in self.products.get_keys():  
                    tkMessageBox.showerror("Update Items","There is at least one item not in the products list.")  
                    do=False  
                    break  
                elif sub_item==item.get_ID():  
                    tkMessageBox.showerror("Update Items","The item could not refer to the compound itself.")  
                    do=False  
                    break  
            if do:  
                item.set_items(new_items_list)  
                self.refresh_listbox()  
        else:  
            tkMessageBox.showerror("Update Items","Invalid Items List.")  
    else:  
        tkMessageBox.showerror("Update Items","No item selected.")  

def push_remove_item(self):  
    key=self.get_key_from_selection()  
    if key!=None:  
        if not self.products.check_depend(key):  
            self.products.remove_item(key)      
            self.refresh_listbox()  
        else:  
            tkMessageBox.showerror("Remove Item","Selected item contained in compound item.")     
    else:  
        tkMessageBox.showerror("Remove Item","No item selected.")  

# Controller part:  

class Controller(object):  
    # This class organise all the controllers in the window.  
    def __init__(self, window):  
        # Initialise the View object.  
        self.view=View(window)  
        self.view.pack(side=TOP, ipady=130)  

        # Initialise the menu.   
        self.menu_bar=Menu(window)  
        window['menu']=self.menu_bar  
        self.file_menu=Menu(self.menu_bar)  
        self.menu_bar.add_cascade(label='File', menu=self.file_menu)  
        self.file_menu.add_command(label='Open Products File', command=self.view.push_open_file)  
        self.file_menu.add_command(label='Save Products File', command=self.view.push_save_file)  
        self.file_menu.add_command(label='Exit', command=exit)  

        # Initialise the function buttons, using a Frame to container layout them.  
        self.control_bar=Frame(window, width=150)  
        self.control_bar.pack(side=TOP, pady=10)  
        self.add_part_button=Button(self.control_bar, text="Add Part", command=self.push_add_part)  
        self.add_part_button.pack(side=LEFT, padx=20, anchor=CENTER)  
        self.add_compound_button=Button(self.control_bar, text="Add Compound", command=self.push_add_compound)  
        self.add_compound_button.pack(side=LEFT, padx=20, anchor=CENTER)  
        self.update_name_button=Button(self.control_bar, text="Update Name", command=self.push_update_name)  
        self.update_name_button.pack(side=LEFT, padx=20, anchor=CENTER)  
        self.update_cost_button=Button(self.control_bar, text="Update Cost", command=self.push_update_cost)  
        self.update_cost_button.pack(side=LEFT, padx=20, anchor=CENTER)  
        self.update_items_button=Button(self.control_bar, text="Update Items", command=self.push_update_items)  
        self.update_items_button.pack(side=LEFT, padx=20, anchor=CENTER)  
        self.remove_item_button=Button(self.control_bar, text="Remove Item", command=self.view.push_remove_item)  
        self.remove_item_button.pack(side=LEFT, padx=20, anchor=CENTER)  

        # Initialise the entry area in the botttom, using a Frame to container layout them.  
        self.entry_area=Frame(window, width=150)  
        self.entry_area.pack(side=BOTTOM, pady=10)  
        self.status=Label(self.entry_area, width=20)  
        self.status.pack(side=LEFT, padx=0, anchor=CENTER)  
        self.entry=Entry(self.entry_area, width=80)  
        self.entry.pack(side=LEFT, padx=0, anchor=CENTER)  
        self.OK_button=Button(self.entry_area, text="OK", command=self.push_OK)  
        self.OK_button.pack(side=LEFT, padx=20, anchor=CENTER)  

    # The next 5 methods will be activated after their corresponded buttons are pushed, the actions of them are to change the commandID variable and label text.  
    # The function of this variable is to set the function statue before typing in the entry box.  

    def push_add_part(self):  
        self.commandID=ADD_PART  
        self.status.config(text="Add Part ID")  

    def push_add_compound(self):  
        self.commandID=ADD_COMPOUND  
        self.status.config(text="Add Compound ID")  

    def push_update_name(self):  
        self.commandID=UPDATE_NAME  
        self.status.config(text="Update Name")  

    def push_update_cost(self):  
        self.commandID=UPDATE_COST  
        self.status.config(text="Update Cost")  

    def push_update_items(self):  
        self.commandID=UPDATE_ITEMS  
        self.status.config(text="Update Compound Items")          

    # The operations setted beofre will only be done after OK button pushed.   
    def push_OK(self):  
        if self.commandID==ADD_PART:  
            self.view.add_part(self.entry.get())  
        elif self.commandID==ADD_COMPOUND:  
            self.view.add_compound(self.entry.get())  
        elif self.commandID==UPDATE_NAME:  
            self.view.update_name(self.entry.get())  
        elif self.commandID==UPDATE_COST:  
            self.view.update_cost(self.entry.get())  
        elif self.commandID==UPDATE_ITEMS:  
            self.view.update_items(self.entry.get())  
        # Clear the label box.  
        self.status.config(text='')  
        # Clear the entry box.  
        self.entry.delete(0, END)  
        # Reset the command statue.  
        self.commandID=None  
  • 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-06-12T17:38:46+00:00Added an answer on June 12, 2026 at 5:38 pm

    You’ve defined your “update_cost” button like this:

    self.update_cost_button=Button(..., command=self.push_update_cost)  
    ...
    def push_update_cost(self):  
        self.commandID=UPDATE_COST  
        self.status.config(text="Update Cost")  
    

    Notice that nowhere in push_update_cost() do you actually call the code that would generate the error. The error is generated by the update_cost method on the view, but that method is only called from push_OK, and push_OK is only called as a response to clicking on the OK button.

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

Sidebar

Related Questions

The code below is supposed to get the next record when a button is
My code below is supposed to display each question ($_POST[questionText]). For each question, it
Every time I run the code below it is supposed to come up with
I suppose button should has Close title in the code below, but it has
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
The code below partially works. Its supposed to return all the tables in the
Apple says in the Safari HTML reference that the below code is supposed to
The below code is supposed to print: PHP XPath Example, but it doesn't. I'm
The code below is supposed to check if there is a person in the
I'm having issues with the Java code below. It is supposed to update certain

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.