Teaching myself Python Day 5

in #ulog5 years ago

Added a query for minimum daily temperature and separated out the date. I started adding some code to eventually do error logging which I still need to research some more.

pylearnday5.png

import datetime
import time
import MySQLdb
from tkinter import *
from tkinter.ttk import *
import logging
log = logging.getLogger("pylearn-day5")
logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(levelname)s %(message)s',
                    filename='pylearn.log',
                    filemode='w')
log.info("Starting program")

window =Tk()
window.title("Pylearn Day 5")
window.geometry('1024x768')
lbl = Label(window, text="day 5", font=("Arial Bold", 50))
lbl.pack()
lbl1 = Label(window, text="label 1", font=("Arial Bold", 30))
lbl1.pack()
lbl2 = Label(window, text="label 2", font=("Arial Bold", 30))
lbl2.pack()

querydate = str(datetime.date.today())

def clicked2():
    db = MySQLdb.connect("192.168.1.200", "pidata", "Rasp!data99", "home_data")
    cursor = db.cursor()
    sqlcmd = "select min(temp) from temperatures where tempTime like '" + querydate + "%' and location like 'RearDeck';"
    cursor.execute(sqlcmd)
    row = cursor.fetchone()
    lbl.configure(text= querydate, font=("Arial Bold", 24))
    lbl1.configure(text= "  Min Temp " + str(row[0]), font=("Arial Bold", 24))
    sqlcmd = "select max(temp) from temperatures where tempTime like '" + querydate + "%' and location like 'RearDeck';"
    cursor.execute(sqlcmd)
    row = cursor.fetchone()
    lbl2.configure(text= "  Max Temp " + str(row[0]), font=("Arial Bold", 24))
    
    db.close()

button_2 = Button(window, text="Click for max temp", command=clicked2)
button_2.pack()

window.mainloop()
Sort:  

Is tkinter easy to learn?

The basic's are easy, but I have not figured out the layout stuff yet. I like the fact that it is included in current Python installs and that makes it easy to use anywhere without dependencies. Next I will have to figure out what Python web framework to learn for creating simple web pages with my data.

Thats nice. I'm slowly getting back into python(data processing is so nice with python). Maybe its time to see if I can make some desktop applications.

Slowly but surely you will get there.