[Tkinter-discuss] confused on grid positioning vs. imports

Bryan Oakley bryan.oakley at gmail.com
Fri Mar 8 17:26:10 CET 2013


On Fri, Mar 8, 2013 at 10:18 AM, Monte Milanuk <memilanuk at gmail.com> wrote:
> Bryan Oakley <bryan.oakley <at> gmail.com> writes:
>
>> My advice:
>>
>> Always do it this way:
>>
>>     import Tkinter as tk
>>     import ttk
>>
>> There! Now there's no global namespace pollution, and everything's
>> accessible. Plus, it becomes immediately clear whether you're using
>> ttk widgets or tkinter widgets: ttk..Button(...) or tk.Button(...).
>> Your code becomes more self documenting. Also, if you switch to
>> python3 you have to change just the imports and everything should
>> continue to work.
>
> I had considered this... but was concerned that it might cause some
> confusion with widgets having similar names such as 'tk.foo()' and
> 'ttk.foo()'.  I'll have to give it a try and see how it feels in
> practice.

The advantage to this is that it _removes_ the confusion. With this,
it will always be clear which foo() you're working with.

>> As for the constants, with this scheme you would use tk.BOTH, etc.
>> Personally I'm in favor of never using the constants; I see no value
>> in them. These things truly are constants in the underlying tk
>> plumbing, so you can just use the literal string "both', "n", etc
>> rather than the constants. There's simply no need to use a constant
>> named BOTH when you can use "both".  Plus, isn't "nsew" better than
>> N+S+E+W?
>>
>
> I'm a little fuzzy here on exactly what you mean by 'constants'...
> I thought 'both', S+E, etc. were parameters for a function call, not
> constants...

They are just variables that contain strings. Yes, you can use them as
parameters to a function call, but the literal strings work just as
well.


More information about the Tkinter-discuss mailing list