Python GUI questions

Ranting Rick rantingrickjohnson at gmail.com
Tue Mar 19 22:16:25 EDT 2013


On Mar 19, 8:25 pm, maiden129 <sengokubasarafe... at gmail.com> wrote:

> Here is my try to answer some of questions:
>
> [snip code]
I don't understand why you are wrapping this code into a class. Are
you trying to create something reuseable?

> I'm just struggling with only how to create an object that
> will hold a single character that the user will enter.

I would suggest that you scrape this code and start over, and a good
starting point would be at the BEGINNING.

All (well, *most*) GUI applications begin with a "root window". Once
you have created the main window you can start placing widgets inside
the window. This is the basic outline of a Tkinter GUI application.

1. Create the root window.
2. Create all the needed sub-widgets and arrange them properly.
3. Start processing user events.

So using the code you provided (and rearranging it to make sense) you
would end up with this:

## START CODE ##(Python 3.x)
import tkinter as tk
from tkinter.constants import LEFT

def cbButton(self):
    print('I should do something here!')

root = tk.Tk()
root.title("Window")
w=tk.Label(root, text="Enter a string")
w.pack(side=LEFT)
e1 = tk.Entry(root, bd=5)
e1.pack(side=LEFT)
b=tk.Button(root, text="Count", command=cbButton)
b.pack(padx=5, pady=5)
root.mainloop()
## END CODE ##

Notice that i used a more intelligent form of import that will
maintain a clean namespace. Tkinter is a very BLOATED module, and
since you are just learning you won't be aware of the names that could
cause problems.

Also notice that my style is consistent. Not following an accepted
coding style is condemnable, however, being inconsistent with your
style is abominable!

PS: Also, trim those excessive quotes please.



More information about the Python-list mailing list