Created
April 21, 2014 09:07
-
-
Save kuchida1981/11137024 to your computer and use it in GitHub Desktop.
Tkinterネタ pack() のデフォルト動作を変える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
u""" pack()によるウィジェット配置のデフォルト動作を変更する | |
`pack()` するときには、 `pack(expand = True, fill = BOTH)` とすること多いので | |
使用例 | |
from tttk import * | |
root = Tk() | |
Button(master = root, text = 'click me!').pack() | |
root.mainloop() | |
これと同じになる | |
Button(master = root, text = 'click me!').pack(expand = True, fill = BOTH) | |
もっと良いやり方はあるかも……。 | |
""" | |
from Tkinter import * | |
from ttk import * | |
def _pack(self, cnf = {}, **kw): | |
pack_default = ( | |
('expand', True, ), | |
('fill', BOTH, ), | |
) | |
for key, defalut_value in pack_default: | |
if key not in kw: kw[key] = defalut_value | |
Pack.pack_configure(self, cnf, **kw) | |
setattr(Pack, 'pack', _pack) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment