So i'm building a project macro tracker using Python Gui Tkinter module. I'm now trying to extra data from an SQLite database. The data extracted is type Int and I need to convert this to an IntVar so that I can use it as a textvariable in Tkinter's Label. The Label(textvariable=) method required it be an IntVar in this case.
So just to summarize I need to convert an Int variable to an IntVar variable
Any help would be great,
def display_daily_macros():
daily = sqlite3.connect('daily.db')
data = pandas.read_sql_query("Select * from day", daily)
data_time = data[data['sqltime'] == "2020-09-11"]
all_info = data_time.sum()
protein = all_info['Protein']
print(type(protein))
You could do something like this,
from tkinter import *
root = Tk()
protien = '3' #this could be your value from the database
h = IntVar(value=protien) #declaring an IntVar and setting it to protien
e = Entry(root,textvariable=h) #assigning it to the entry widget
e.pack()
root.mainloop()
Here your defining an IntVar()
and then later using the set()
method to make it protien
.
Hope this is what your looking for.
Cheers
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.