Creating a temperature program using Python and Tkinter Creating a temperature program using Python and Tkinter tkinter tkinter

Creating a temperature program using Python and Tkinter


This is my favorite resource for Tkinter: http://effbot.org/tkinterbook/

The title can be a label: http://effbot.org/tkinterbook/label.htm

w = Label(master, text="Hello, world!")w.grid(column=1,row=1)

For everything else, create an entry widget for:

textBox = Text(self, height=1,width=1)textBox.grid(sticky=E,column=1,row=1)

Then insert the data like so:

self.textBox.insert('end',yourText)


Hi there I think I understand what you're trying to accomplish, I recommend using ttk.Treeview for making the table, it's a really useful tool, although it might seen difficult to work

here is a small example to help you see what I mean

from Tkinter import *import ttkclass App:    def __init__(self, master):        frame = Frame(master)        frame.pack()        self.hi_there = Button(frame, text="All Years", command=self.All)        self.hi_there.pack(side=LEFT)        self.hi_there = Button(frame, text="2011", command=self.Y1)        self.hi_there.pack(side=LEFT)        self.hi_there = Button(frame, text="2012", command=self.Y2)        self.hi_there.pack(side=LEFT)        self.hi_there = Button(frame, text="2013", command=self.Y3)        self.hi_there.pack(side=LEFT)        self.hi_there = Button(frame, text="Save & Exit", command=self.Exit)        self.hi_there.pack(side=LEFT)        frame2 = Frame(master)        frame2.pack()        treedata = [('column 1', 'column 2'), ('column 1', 'column 2')]        column_names = ("heading1", "heading2")        tree = ttk.Treeview(frame2, columns = column_names)        for x in treedata:            tree.insert('', 'end', values =x)        for col in column_names:             tree.heading(col, text = col.Title())        tree.pack()

hope this helps there isn't a lot of docs on this, but google will help, one very helpful link: http://www.tkdocs.com/tutorial/tree.html

good luck :)

if you need any more help just ask in a comment :)


An option you may want to consider is instead of using tkinter's .pack() function, use the .grid() function. This allows you to much more dynamically arrange your objects into the way you want it, and works great for what you're doing (creating a grid).

Once you do that, you can take the csv file information and save the text as a variable (let's say csvText). Then, print the variable as a label using:

dataText = Tkinter.Label(root,text=csvText)dataText.grid(row=2,column=0)

and do that for each piece of information. The title at the top would be packed into the grid the same way, except using the columnspan attribute:

title = Tkinter.Label(root,text="TITLE")title.grid(row=1,column=0,columnspan=4)

Your buttons would be the same, except instead of using .pack(side=LEFT), you would pack them by doing:

self.hi_there = Button(frame, text="All Years", command=self.All)self.hi_there.grid(row=0,column=0)self.hi_there = Button(frame, text="2011", command=self.Y1)self.hi_there.grid(row=0,column=1)self.hi_there = Button(frame, text="2012", command=self.Y2)self.hi_there.grid(row=0,column=2)self.hi_there = Button(frame, text="2013", command=self.Y3)self.hi_there.grid(row=0,column=3)self.hi_there = Button(frame, text="Save & Exit", command=self.Exit)self.hi_there.grid(row=0,column=4)

All the button functions would then have to be is finding the new csv information, storing them in the same csvText variables, and passing those on to an update function that updates the labels. Note that when you redraw something to the screen, It won't wipe everything and start from scratch, so when redrawing, don't redraw all of the buttons and the title, just redraw all of your labels. That will save you lines of code and make it slightly more optimized.