The reference to the global name 'start' is not recognized: Tkinter

Encountering the error message "Global name 'start' is not defined" from the code snippet provided. Interestingly, the call to start(panel) within displayImage(img) is responsible for displaying the desired image in the GUI; without it, no image appears. Despite this functionality, the aforementioned error arises. The program is being executed on Ubuntu 12.04 and I am a newcomer to both Python and Tkinter. Any suggestions for resolving this issue? Edit: Image addition takes place during runtime triggered by a button click that invokes loadPicture(file).

import numpy as np
from Tkinter import *
import cv2 as cv
from tkFileDialog import askopenfilename
import tkSimpleDialog as td
import math as mt
from PIL import ImageTk, Image

### General functions #############################################

def raiseFileChooser():
    global filename
    filename = askopenfilename()
    loadPicture(filename)

def loadPicture(file):
# set global variable for other uses
    global img
    img = cv.imread(file, 1) 
    img = cv.cvtColor(img, cv.COLOR_RGB2BGR) 
    displayImage(img, display1)   

def displayImage(image, panel):
    temp = Image.fromarray(image)
    bk = ImageTk.PhotoImage(temp)
    bkLabel = Label(display1, image = bk)
    bkLabel.place(x=0, y=0, relwidth=1, relheight=1)
    start(panel)

### Start App ###########################################

#### get GUI started
root = Tk()
np.set_printoptions(threshold=np.nan)  # so I can print entire arrays

### global variables ####################################
relStatus = StringVar()
relStatus.set(None)
text = StringVar()
filepath = StringVar()
filename = "No file chosen"
img = None
gsc = None
eStatus = StringVar()
eStatus.set(None)
display1 = None
display2 = None

### GUI #################################################
root.title("Picture Transformer")
root.geometry("700x600")

app = PanedWindow(root)
app.pack(padx=20, pady=20)

#Button Panel##############
buttonPanel = Frame(app,width=200, height = 400)
buttonPanel.pack(side=LEFT)

chooser = Button(buttonPanel, text="Choose File", height=1, width=9, command=raiseFileChooser)
chooser.pack()

#set up display panels ###########################
display1 = Frame(app, width=900, height=900, bg="#cccccc")
display1.pack(side=LEFT, fill=BOTH, expand=1)

root.mainloop()

Edit: Stacktrace:

Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "hw2.py", line 78, in raiseFileChooser
loadPicture(filename)
File "hw2.py", line 86, in loadPicture
start(panel)
NameError: global name 'start' is not defined

Answer №1

Your code is missing a global start function, which is causing the error message you are seeing. It seems like there is no start method defined anywhere in your code. Have you checked if there is any documentation suggesting that you should be using a function named start?

It appears that you are running your script in IDLE, and when the non-existent start function is called, it leads to a crash. This crash might bring you back to IDLE, with any windows created up to that point visible on your screen.

An obvious issue in your code is the absence of creating a root window. Make sure to add this line early in your script, before creating any widgets or instances of StringVar:

root = Tk()

Answer №2

Using root.mainloop() instead of start() is effective in this scenario.

Answer №3

Give it a shot

panel.start()

This could potentially help resolve the issue. Why not give it a try?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I determine the smallest word value among multiple files using Python?

I have a collection of 1000 .txt files, each containing data that I need to process using the following code. My goal is to identify the largest value associated with ENSG in each file and remove any other occurrences of ENSG with values lower than the hig ...

Mastering the art of Python to extract all XPATHs from any website

Is there a method to extract product listings from various websites without needing to manually loop through each XPATH? Some sites like Amazon and Alibaba display up to 10 products per page, while others may have 20. I am looking for a way to retrieve a ...

Are mistake entries in a DataFrame using .loc in Pandas a bug or a misunderstanding?

Is there a way to update the contents of an excel file using values from a Python dictionary? I've been trying to use the .loc function, but it seems to be working inconsistently. Sometimes it writes the correct values, and other times it writes the c ...

Measuring data significance using Pandas

My Pandas dataframe looks like this: name domain rank1 rank2 rank3 ... rank_mean foo foo.com 1 1 2 ... 1.34 boo boo.it 5 12 ... 6.4 test test.eu 2 2 ... 2.6 The column ...

Exploring the power of nesting descriptors and decorators in Python

I'm struggling to comprehend the behavior when attempting to nest descriptors or decorators in Python 2.7. For instance, let's consider these simplified versions of property and classmethod: class MyProperty(object): def __init__(self, fget ...

Record a particular message

When I encountered this error, it reminded me of a situation where I was pulling CSV data from a website, but the subscription had expired. The specific error message 'At least one sheet must be visible. Verify that your subscription with blabla.com i ...

Error encountered due to node creation override

Recently, I've been delving into learning Python to enhance my workflow in The Foundry NUKE. One of the things I've been experimenting with is creating overrides that modify nodes upon their creation. Specifically, I had set up an override for a ...

Analyzing PCAP files with Python 2.6

I am looking to analyze information within a data packet captured. I have tried using examples to test my code, but it always results in an error. Below is the snippet of code that causes trouble: import dpkt import sys f = open('test.pcap') pc ...

Track the consecutive row values, but restart the count with each occurrence of 0 in the row

My goal is to analyze consecutive row values in a dataframe and calculate the sum of runs in column A, storing the result in a new column B. The script should iterate through column A, counting consecutive occurrences of '1s'. When encountering ...

What is the process for starting a Dash App that is contained within a package that has already been installed?

In the process of developing a package, I have structured it with a module containing functions (fed3live.py) and another with a Dash App (fed3_app.py). Here is how the package is organized: fed3live/ ├─__init__.py ├─fed3live/ │ └─fed3live.py ...

Find the button for uploading files using Selenium

I am encountering an issue with trying to click the button displayed below (image and HTML). Despite attempting to locate it using both xpath and ID, Selenium is still unable to find it. https://i.stack.imgur.com/KMMku.png <input id="wsUpload1" type= ...

Having trouble updating Django forms.py with the latest values from the database

models.py class Test(models.Model): name = models.CharField(max_length=256) slug_name = models.CharField(max_length=256) template = models.BooleanField("Is Template",default=False) @staticmethod def template_as_tuple(): return ...

Automating pagination with Selenium

Currently, I am experimenting with using selenium to automate pagination by navigating through "next" buttons. My goal is to apply this technique on a large scale, potentially spanning hundreds of pages. While I have successfully implemented the functional ...

Can Python be used to extract the following text element from HTML?

Hello, I am currently on a quest to locate "FIND THIS" and transform it into "GET THIS" within the HTML code provided below. a= '''<tr> <td colspan="2" width="268"> <span style="width:268px;font-size:1 ...

Python's selenium code appears to halt at the click function, even though the button has been successfully clicked

After clicking the button, the code stops and does not continue. print("I'm going to click on the toaster") site.find_element(By.XPATH,"//div[text()='Click to view']").click() print("The toaster was clicked") When Python clicks the button, ...

Set all option elements to have identical values

I am struggling to make all the rounds uniform, as I can only change the first one. Currently, all player scorecards are open, but I need to be able to select the same round for each of them. Let's ignore all the imports, as I was experimenting with ...

What is the most effective way to organize dictionary-like observations based on time in Pandas?

Looking to analyze a large dataset of observations tied to specific datetimes that can be represented either as dictionary objects or custom objects. Here's an example: Datetime | Data -------------------------------------------------------- ...

Is there a method to merge elements from two separate "lists of lists" that contain the same elements but have different lengths within each list?

In an attempt to merge two distinct lists of lists based on shared elements, I find myself faced with a challenge. Consider the following: list1 = [['a1', 'a2', 'b2'], ['h1', 'h2'], ['c1', ' ...

What is the rationale behind assigning names to variables in Tensorflow?

During my observation in various locations, I noticed a pattern in variable initialization where some were assigned names while others were not. For instance: # Named var = tf.Variable(0, name="counter") # Unnamed one = tf.constant(1) What is the signif ...

Discover the Practical Utility of Maps beyond Hash Tables in Everyday Life

I am currently attempting to explain the concept of Maps (also known as hash tables or dictionaries) to someone who is a beginner in programming. While most people are familiar with the concepts of Arrays (a list of things) and Sets (a bag of things), I ...