[Tutor] Python GUI Tkinter Button arrangement

Alan Gauld alan.gauld at btinternet.com
Thu Feb 17 01:13:13 CET 2011


"Ganesh Kumar" <bugcy013 at gmail.com> wrote

> I am new to python , i have creating one application user
> agreement..using Tkinter, The Content
> of the agreement will reading one file...Agree button will click 
> means
> enable next button. And activate script,

I'm assuming by User Agreement you mean User Interface?
Maybe some translation software giving strange results?

> all are working but one buttons are top of the screen.
> i want button in bottom of the frame plz. help me..

It would help if you were a bit more explicit.
Which button is in the wrong place?

> this my source code
> http://pastebin.com/Lm5teAtS

There are lots of strange things here.
Can I suggest you keep it as simple as possible to start with.
And you should certainly not mix GUI tookits. You have
Tkinter, wx and GTk all included here. If you use Tkinter stick
with that.

Also there is no real need for ttk here yet - once you get
it working you can add some ttk to make it look pretty
but for now I'd stick with plain old Tkinter. (In fact I'd do
the same with PMW, but it does at least give you the
scrolling text box...)

I'm not sure what you think you are doing with the
sys.path line:

sys.path[:0] = ['../../..']

but I strongly suspect its not what you want!

Also it will help if you give your widgets meaningful names.
For example:

widget = Tkinter.Button(self1, text='Next',
                                    command = lambda b='dhana': 
buttonPress(b) )

why not call it nextButton instead of widget. (personally I just
add one or two letters so here it would be a b for Button
and the name would be: bNext) It makes the code much
easier to understand. You do it for the other buttons, why
not that one?

Also its usually better to keep all the widget construction in a
single place. You have widgets being constructed in 2 different
functions: init and initUI.

I have no idea what defaultKey() is doing. It defines a function
internally which is never used then calls  the main Tk() function
(I assume tk() is a mistake?) But Tk() should only be called once
in an app.

I think the line

if a1 == 1:

should be indented.

Finally, it's slightly unusual in a Tkinter app to define the
event handler functions inside the GUI building function.
It will work but it does mean those evenmt handlers are
invisible to the rest of the app which might limit your
flexibility to reuse them later

All in all it seems like a lot of complexity for what should
be a very simple application. Of course you may be
intending to change the structure to include much more
complex handler functions later. But as it stands it seems
complex for what it does.
.
HTH
-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list