Skip to content

Instantly share code, notes, and snippets.

@kuchida1981
Created April 21, 2014 09:07
Show Gist options
  • Save kuchida1981/11137024 to your computer and use it in GitHub Desktop.
Save kuchida1981/11137024 to your computer and use it in GitHub Desktop.
Tkinterネタ pack() のデフォルト動作を変える
# 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