Teaching myself Python Day 3

in ulog •  6 months ago 

Now the code queries a database and displays a value when pressing the button. Need to learn how to better arrange the button and text output in the window.

pylearnday3.png

import MySQLdb
from tkinter import *
from tkinter.ttk import *

window =Tk()
window.title("Pylearn Day 3")
window.geometry('1024x768')
lbl = Label(window, text="hello", font=("Arial Bold", 50))
lbl.grid(column=100, row=10)
def clicked2():
    db = MySQLdb.connect("192.168.1.200", "pidata", "Rasp!data99", "home_data")
    cursor = db.cursor()
    sqlcmd = "select max(temp) from temperatures where tempTime like '2019-09-24%';"
    cursor.execute(sqlcmd)
    row = cursor.fetchone()
    lbl.configure(text= "Max Temp " + str(row[0]), font=("Arial Bold", 14))
    db.close()
button_2 = Button(window, text="Click Me!", command=clicked2)
button_2.grid(column=2, row=9)

window.mainloop()

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...
Loading...