Python Forum
ReferenceError: weakly-referenced object no longer exists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ReferenceError: weakly-referenced object no longer exists
#15
The following code is search_book.py, which will be imported into main.py

Full Code:

from tkinter import *
from tkinter import messagebox
from tkinter import StringVar
import tkinter.ttk
import pyautogui as pg
import mysql.connector as mc

def search_book():
    global password, username
    usern = pg.prompt("Username", "Enter your username")
    passw = pg.password("Password", "Enter your password")
    try:
        conn = mc.connect(host="localhost", db="Library", user=usern, passwd=passw)
    except:
        messagebox.showerror("Incorrect Credentials", "Those credentials are incorrect")
        exit()

    global cur
    cur = conn.cursor()
    form = Tk()
    form.geometry("500x200")
    form.resizable(False, False)
    form.title("Search for a book")
    top_lbl = Label(form, text="Search For A Book", font="Courier 26").pack()
    
    OptionList = [
    "Pick A Search Type",
    "Title",
    "Author",
    "ISBN",
    ] 

    global variable
    variable = StringVar(form)
    variable.set(OptionList[0])

    search_dropd = OptionMenu(form, variable, *OptionList)
    search_dropd.pack()

    global search_entr
    search_entr = Entry(form, width=45)
    search_entr.pack()

    submit_btn = Button(text="SUBMIT", command=submit, width=34).pack()
        

def submit():
    search_words = search_entr.get()
    search_type = variable.get()
    if search_type == "Pick A Search Type":
        messagebox.showerror("Invalid Choice", "'Pick A Search Type' is not a valid search type.")
    else:
        global results
        if search_type == "ISBN":
            cur.execute("SELECT * FROM Books WHERE ISBN = %s", (search_words,))
            results = cur.fetchball()
        if search_type == 'Title':
            cur.execute("SELECT * FROM Books where ITLE = %s", (search_words,))
            results = cur.fetchball()
        if search_type == "Author":
            cur.execute("SELECT * FROM Books WHERE AUTHOR = %s", (search_words,))
            results = cur.fetchball()

        show_results(results)
    
def show_results(results_list):
    for i in range(len(results_list)):
        print(results_list[i])
Reply


Messages In This Thread
RE: ReferenceError: weakly-referenced object no longer exists - by MrBitPythoner - Dec-14-2020, 06:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Upgraded Python: Module no longer found - for Linux Curbie 8 1,328 Mar-05-2025, 06:01 PM
Last Post: Curbie
Question [SOLVED] Upgraded Python: Module no longer found Winfried 1 958 Jan-01-2025, 02:43 PM
Last Post: Larz60+
  how solve: local variable referenced before assignment ? trix 5 1,647 Jun-15-2024, 07:15 PM
Last Post: trix
  Beginner: Code not work when longer list raiviscoding 2 1,614 May-19-2023, 11:19 AM
Last Post: deanhystad
  local varible referenced before assignment SC4R 6 2,985 Jan-10-2023, 10:58 PM
Last Post: snippsat
  a longer docstring Skaperen 8 3,526 Aug-25-2022, 11:21 PM
Last Post: Skaperen
  UnboundLocalError: local variable 'wmi' referenced before assignment ilknurg 2 2,904 Feb-10-2022, 07:36 PM
Last Post: deanhystad
  Referenced before assignment finndude 3 4,200 Mar-02-2021, 08:11 PM
Last Post: finndude
  IDLE editing window no longer works chris1 2 3,047 Feb-06-2021, 07:59 AM
Last Post: chris1
  Code no longer working yk303 14 14,518 Dec-21-2020, 10:58 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020