Tkinter: 2009年5月アーカイブ



最近Tkinter使ってます。id:rokujyouhitomaです。



簡単なGUIを作るのに適してるTkinterですが、弱点が。なんと...表部品(テーブル部品)がない!!



まさか表部品の実装をしなければいけないのだろうか...。



調べて分かったのですが...正確に言うと、TkinterにないのではなくTkにないです。


でさらに調べたところ、sourcefoge.netに公開されてました^^


環境


Mac OS 10.5


インストール


インストールはmake, make installとmacportsがある。


./configure, make, make install

sourcefoge.netに公開されているので早速入れる。



$ curl -O http://nchc.dl.sourceforge.net/sourceforge/tktable/Tktable2.10.tar.gz
$ tar zxvf Tktable2.10.tar.gz

$ cd Tktable2.10

$ ./configure
$ make
# make install

完了!


macports


$ sudo port install tktable

入ったか確認。


直接tclコマンドを叩く。



$ tclsh
$ package require Tktable

正しければ、



$ 2.9

と表示される。


正しくなければ、



$ can't find package Tktable

と表示される。


補足:終了はexit


Pythonで利用する。


解凍したTktable2.10.tar.gzの中にPython用のモジュールが入ってます。


デモは、


demos/tktable.py


f:id:rokujyouhitoma:20090515175613p:image


ライブラリは、


library/tktable.py


試しに実行。


import tktable
table = tktable.Table(rows=5, cols = 5)
table.pack()

実行結果

こんな感じで表になります。


f:id:rokujyouhitoma:20090515180241p:image


入力もできちゃったり。


f:id:rokujyouhitoma:20090515180422p:image



これで、開発が進む。実装するのは楽しそうだけどしんどいもんね...


参考


公式


その他



最近業務でTkinter使ってるのでメモ書きと陥ったところ。


そもそもTkinterって何よ?


TkinterはPythonの標準モジュールで、Tk/Tclをラップしてるモジュール。


TkはGUIツールキット(Tool Kit)の一種でSun Microsystemsが開発していたライブラリ。


環境



  • Mac OS 10.5

  • Python2.6.2


wmに引っかかった...


自身の知識不足でひっかかった所は、ウィンドウのアイコンに.icoを設定しようと考えていた。


調べたところwm_iconbitmapというメソッドを発見。このメソッドに.icoへのファイルパスを設定。


実行したところ...



return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "star.ico" not defined


エラーがでる。


調べた結果...



> I know that in a normal windows python Tkinter app you would use:


>


> root.wm_iconbitmap("/Icons for App/Windows.ico")


>


> to make an icon in the title bar. However, when you do that in mac OSX you


> can't see it. I am not sure if it is because the x - and+ are on the left


> side, or because it just doesn't support MacOSX. Looking at other programs


> none of them have it either. I am just wondering is it possible to put an


> icon in the top title bar.


>


... [show rest of quote]


No, OS X doesn't support this, as far as I know.



あちゃー。Macはサポート外ですが...残念。


という事で、下記に修正し完了。



import sys

if sys.platform == "win32":
root.wm_iconbitmap("star.ico")


細かな所だけど、Macでも設定したいな...


参考


トップレベルのウィンドウの制御 トップレベルのウィンドウ


Re: Icon on title bar in macOSX