This is a personal record of my python programming experiences. It will allow me to see how I am progressing as I learn a new language.
Thursday, December 23, 2010
Simple image displayer
I created a very simple image displayer using python's canvas widget. It will only display gif files, so converted a jpeg image with gimp. I don't know how to make the image fit in the window yet, but I can adjust the canvas size, and what part of the photo is showing on the canvas.
Friday, November 12, 2010
SQLite and Python
I created a table using SQLite, and then I wrote a simple function in python to list the data. I made a GUI button to execute the function too. It's not much, but it is a start.
Wednesday, November 10, 2010
Executing SQL commands in python
#database code for learning purposes
import sqlite3
connectdb=sqlite3.connect('mydata.db') #Create data base named mydata.db on disk
c=conn.cursor() #Create a cursor object so SQL commands can be executed
#Create a table named deedrecord
c.execute("create table deedrecord (deed text,grantor text,grantee text,deeddate text)")
#Add some records to the table
c.execute("insert into deedrecord values ('1234123','mickey mouse','donald duck','111010')")
c.execute("insert into deedrecord values ('3456345','steve atchison','ronald regan','110910')")
therows=c.execute("select * from deedrecord")
for rows in therows:
print(rows[0])
print(rows[1])
print(rows[2])
print(rows[3])
Saturday, October 23, 2010
Thursday, October 21, 2010
Program I wrote for work
from Tkinter import *
import tkMessageBox
#Written by Shawnee County Mapping Department
def listfile():
fob=open('BFEcalc.txt','r')
textField.delete('1.0',END) #Clears text widget
for eachline in fob:
textField.insert('1.0',eachline)
fob.close()
def calcStream():
#Get data from entry widgets
EL2=float(lowElevation.get())
EL1=float(highElevation.get())
D2=float(streamDist.get())
D1=float(Measure.get())
theRise = D1*((EL1-EL2)/D2)
theBFE = theRise+EL2
#Clear entry widgets
lowElevation.delete(0,END)
highElevation.delete(0,END)
streamDist.delete(0,END)
Measure.delete(0,END)
#Open a file and write data to it
if EL2 < EL1 and D2 > D1:
fob=open("BFEcalc.txt","a")
fob.write('-------------------------------\n')
fob.write('Low elvevation = %s\n' % str(EL2))
fob.write('High elevation = %s\n' % str(EL1))
fob.write('Stream dist = %s\n' % str(D2))
fob.write('Measure dist = %s\n' % str(D1))
fob.write('The rise = %s \n' % str(theRise))
fob.write('The BFE = %s \n' % str(theBFE))
fob.write('Address:%s '%propAdd.get()+'\n')
fob.close()
#tkMessageBox.showinfo(title='SNCO calculator',message="The BFE = %.3f \n The rise = %.3f" %(theBFE,theRise) )
listfile()
propAdd.delete(0,END)
else:
tkMessageBox.showerror(' ','Error in input data')
#GUI code
root = Tk()
root.geometry('200x400')
root.config(bg='blue')
Label(root,text='Higher elevation (EL 1)').pack(padx=5,pady=5)
highElevation = Entry()
highElevation.pack()
Label(root,text='Lower Elevation (EL 2)').pack(padx=5,pady=5)
lowElevation = Entry()
lowElevation.pack()
Label(root,text='Measurement (D 1)').pack(padx=5,pady=5)
Measure=Entry()
Measure.pack()
Label(root,text='Stream Distance (D 2)').pack(padx=5,pady=5)
streamDist=Entry()
streamDist.pack()
Label(root,text='Property address').pack(padx=5,pady=5)
propAdd=Entry(root)
propAdd.pack()
aButton=Button(root,text='Calculate',command=calcStream)
aButton.pack(padx=5,pady=5)
aButton2=Button(root,text='list file',command=listfile)
aButton2.pack()
textField=Text(root)
textField.pack(padx=2,pady=2)
root.mainloop()
Tuesday, September 28, 2010
I learned how to make a "Desktop Launcher"
I right clicked on my desktop and created a desktop launcher for my gas mileage program. The code is pasted below.
#!/usr/bin/python
#Gas mileage calculator written in version 2.6
#This program helps me keep track of my gas mileage!
from Tkinter import *
def calcMPG():
theGallons = galEntry.get()
theMiles = milesEntry.get()
milesPerGallon = float(theGallons)/float(theMiles),'miles per gallon'
print milesPerGallon
#open a file and write to it.
fob = open('Aveo_MPG.txt','a')
fob.write('------------------------------')
fob.write('\n')
fob.write(str(theGallons)+galEntry.get()+'\n')
fob.write('Miles = '+milesEntry.get()+'\n')
fob.write(str(milesPerGallon)+'\n')
fob.close
#Clear the entry widgets!
galEntry.delete(0,END)
milesEntry.delete(0,END)
#open Aveo_MPG file and list it. THIS WORKS GREAT!
def show():
fob = open('Aveo_MPG.txt','r')
for eachline in fob:
print eachline
fob.close()
root = Tk()
root.config(bg='blue')
aLable = Label(root,text="Miles")
aLable.pack()
galEntry = Entry(root)
galEntry.pack(padx=5,pady=5)
aLable2=Label(root,text="Gallons")
aLable2.pack()
milesEntry=Entry(root)
milesEntry.pack(padx=5,pady=5)
btn1= Button(root,text='Calc MPG', command = calcMPG)
btn1.pack(padx=5,pady=5)
btn2=Button(root,text='Show list',command=show)
btn2.pack(padx=5,pady=5)
root.mainloop()
#!/usr/bin/python
#Gas mileage calculator written in version 2.6
#This program helps me keep track of my gas mileage!
from Tkinter import *
def calcMPG():
theGallons = galEntry.get()
theMiles = milesEntry.get()
milesPerGallon = float(theGallons)/float(theMiles),'miles per gallon'
print milesPerGallon
#open a file and write to it.
fob = open('Aveo_MPG.txt','a')
fob.write('------------------------------')
fob.write('\n')
fob.write(str(theGallons)+galEntry.get()+'\n')
fob.write('Miles = '+milesEntry.get()+'\n')
fob.write(str(milesPerGallon)+'\n')
fob.close
#Clear the entry widgets!
galEntry.delete(0,END)
milesEntry.delete(0,END)
#open Aveo_MPG file and list it. THIS WORKS GREAT!
def show():
fob = open('Aveo_MPG.txt','r')
for eachline in fob:
print eachline
fob.close()
root = Tk()
root.config(bg='blue')
aLable = Label(root,text="Miles")
aLable.pack()
galEntry = Entry(root)
galEntry.pack(padx=5,pady=5)
aLable2=Label(root,text="Gallons")
aLable2.pack()
milesEntry=Entry(root)
milesEntry.pack(padx=5,pady=5)
btn1= Button(root,text='Calc MPG', command = calcMPG)
btn1.pack(padx=5,pady=5)
btn2=Button(root,text='Show list',command=show)
btn2.pack(padx=5,pady=5)
root.mainloop()
Tiny snippet of code that opens a webbrowser.
from Tkinter import *
import webbrowser
def opensnco():
webbrowser.open('http://www.snco.us/')
root=Tk()
btn1=Button(root,text='Open SNCO ',command=opensnco)
btn1.pack()
root.mainloop()
import webbrowser
def opensnco():
webbrowser.open('http://www.snco.us/')
root=Tk()
btn1=Button(root,text='Open SNCO ',command=opensnco)
btn1.pack()
root.mainloop()
Subscribe to:
Posts (Atom)
Followers
Blog Archive
- June (1)
- March (3)
- February (1)
- July (3)
- May (1)
- April (1)
- March (1)
- January (1)
- December (1)
- November (4)
- July (3)
- May (2)
- April (1)
- March (6)
- February (2)
- December (1)
- November (1)
- September (3)
- August (3)
- July (1)
- March (3)
- January (1)
- December (5)
- November (2)
- October (1)
- September (2)
- August (1)
- July (4)
- May (3)
- February (1)
- January (1)
- December (1)
- November (2)
- October (2)
- September (9)
- August (2)
- May (1)
- April (1)
- March (6)
- February (5)
- January (3)
- August (2)



