What is a Weak Reference and Where am I using it? (1 Viewer)

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 19:29
Joined
Mar 22, 2009
Messages
876
Python:
from tkinter import *
import pymysql
import mysql.connector
connection = pymysql.connect(host="shafty",
                             user="root",
                             password="abc123",
                             database="Mubarak")
cursor = connection.cursor()
MainWindow = Tk()
MainWindow.title("Main Form")
NameLabel = Label(MainWindow,text="Name",width=7,height=1,anchor="nw")
NameLabel.grid(row=1,column=1)
NameBox = Entry(MainWindow,width=20)
NameBox.grid(row=1,column=2)
AgeLabel = Label(MainWindow,text="Age",width=7,height=1,anchor="nw")
AgeLabel.grid(row=2,column=1)
AgeBox = Entry(MainWindow,width=20)
AgeBox.grid(row=2,column=2)
LocationLabel = Label(MainWindow,text="Location",anchor="nw")
LocationLabel.grid(row=3,column=1)
LocationBox = Entry(MainWindow,width=20)
LocationBox.grid(row=3,column=2)
def PopulateGrid():
    cursor.execute("SELECT * FROM Persons")   
    ReportData = cursor.fetchall()
    import pandas as pd
    ReportFrame = pd.DataFrame(ReportData)
    Report = ReportFrame.to_html(index=False,header=False)
    from tkinterweb import HtmlFrame
    web_frame=HtmlFrame(MainWindow)
    web_frame.grid(row=5,column=2)
    web_frame.load_html(Report)

    from jinja2 import Environment, Template
    env = Environment(loader='file')
    myTemplate = env.get_template("Table.html")
    html_table = ReportFrame.to_html(index=False)
    html_content = myTemplate.render(table_data=html_table)
def Upload():   
    cursor.execute("INSERT INTO Persons (NameVal, Age, Location) values (%s, %s, %s)",
                   (NameBox.get(), AgeBox.get(), LocationBox.get()))
    connection.commit()
    print("SuccessFully Updated!")
    PopulateGrid()
    import tkinter.messagebox as messagebox
    messagebox.showinfo(title="Button Clicked", message="Successfully Uploaded!")
UploadButton = Button(MainWindow,text="Upload",anchor="nw",command=Upload)
UploadButton.grid(row=4,column=2)
PopulateGrid()
MainWindow.mainloop()
I am getting "cannot create weak reference to 'str' object" at the below sentence:
myTemplate = env.get_template("Table.html")
How to avoid it in future? Please explain. Thank You.
 

Users who are viewing this thread

Back
Top Bottom