2 Python GUI Tkinter PIL C #include <stdio.h> main() { int i; for(i=0;i<5;i++) { printf("hello World.\n"); } } Python #! /usr//bin/env python for i in



Similar documents
2 Python GUI Tkinter PIL C #include <stdio.h> main() { int i; for(i=0;i<5;i++) { printf("hello World.\n"); } } Python #! /usr//bin/env python for i in

(pack ) Toplevel

from tkinter import * root = Tk() # variable teban = IntVar() teban.set(1) # def start(): canvas.create_rectangle(0, 0, 560, 560, fill= white ) for k

cards.gif from Tkinter import * root = Tk() c0 = Canvas(root, width = 400, height = 300) c0.pack() image_data = PhotoImage(file = c1.gif ) c0.create_i

Python2 Python3 Python 2.7 Python 3.6 Python2 Python3 Python 2.7 Python3.6 Python Python Anaconda Python Anaconda Python

たのしいプログラミング Pythonではじめよう!

from Tkinter import * root = Tk() c0 = Canvas(root, width = 400, height = 300) c0.pack() image_data = PhotoImage(file = c1.gif ) c0.create_image(200,

2.2 Sage I 11 factor Sage Sage exit quit 1 sage : exit 2 Exiting Sage ( CPU time 0m0.06s, Wall time 2m8.71 s). 2.2 Sage Python Sage 1. Sage.sage 2. sa

ProVisionaire Control V3.0セットアップガイド

tebiki00.dvi

1 1.1 (JCPRG) 30 Nuclear Reaction Data File (NRDF) PC GSYS2.4 JCPRG GSYS2.4 Java Windows, Linux, Max OS X, FreeBSD GUI PNG, GIF, JPEG X Y GSYS2

Python Speed Learning

GNU Emacs GNU Emacs

PowerPoint Presentation

X Window System X X &

version 1.0 November 2010 PyRAF Y. Nakajima Computer and Data Management Division Subaru Telescope NAOJ

グラフ数値読み取りシステム (GSYS2.4) 利用の手引

6 Tgif William Chia-Wei Chang tgif 3.0 pixmap URL Tgif 6.1: Tgif


¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

0.2 Button TextBox: menu tab 2

New version (2.15.1) of Specview is now available Dismiss Windows Specview.bat set spv= Specview set jhome= JAVA (C:\Program Files\Java\jre<version>\

Specview Specview Specview STSCI(Space Telescope SCience Institute) VO Specview Web page htt

Windows Cygwin Mac *1 Emacs Ruby ( ) 1 Cygwin Bash Cygwin Windows Cygwin Cygwin Mac 1 Mac 1.2 *2 ls *3 *1 OS Linux *2 *3 Enter ( ) 2

UNIX

main.dvi

1 VisBAR edu H 2 O.....

programmingII2019-v01

listings-ext


Microsoft Word - Meta70_Preferences.doc

LiveCode初心者開発入門サンプル

0527-PanMark

dTVIIman.PDF

2008 DS T050049

help gem gem gem my help

ohp08.dvi

2 Windows 10 *1 3 Linux 3.1 Windows Bash on Ubuntu on Windows cygwin MacOS Linux OS Ubuntu OS Linux OS 1 GUI Windows Explorer Mac Finder 1 GUI

gnuplot.dvi

I 2 tutimura/ I 2 p.1/??

アセンブラ入門(CASL II) 第3版

Python3 Next 2


untitled

NPCA部誌2018

<4D F736F F D B B83578B6594BB2D834A836F815B82D082C88C60202E646F63>

JavaScript の使い方

1 I EViews View Proc Freeze

r08.dvi

13 Student Software TI-Nspire CX CAS TI Web TI-Nspire CX CAS Student Software ( ) 1 Student Software 37 Student Software Nspire Nspire Nspir

SR-X526R1 サーバ収容スイッチ ご利用にあたって

Pascal Pascal Free Pascal CPad for Pascal Microsoft Windows OS Pascal

スライド タイトルなし

MS-Excel : [ ] [ ] [Applications] [Excel2007] : [Office ] [Excel ] [ ] : [Ctrl+n] [Office ] [ ] : [Ctrl+o] [Office ] [ ] ( ) 2


3 4 17:00 Address: ( ) (Subject) ( ) LeapMotion EyeTribe Processing LeapMotion EyeTribe 1. Mac OS X, LeapMotion, EyeTribe, Proces

グローバル タイトル変換テーブルの編集

Step 1 Feature Extraction Featuer Extraction Feature Extraction Featuer Extraction Image Analysis Start>Programs>Agilent-Life Sciences>Feature Extract

MS-Excel : [ ] [ ] [Applications] [Excel2007] : [Office ] [Excel ] [ ] : [Ctrl+n] [Office ] [ ] : [Ctrl+o] [Office ] [ ] ( ) 2

2 1. Ubuntu 1.1 OS OS OS ( OS ) OS ( OS ) VMware Player VMware Player jp/download/player/ URL VMware Plaeyr VMware

BRADY Worldwide, Inc. BRADY BRADY BRADY BMP 51 BRADY Worldwide, Inc. Microsoft Windows Microsoft BRADY 2011 BRADY Worldwide, Inc. All Rights Reserved

SystemC言語概論

Tcl/Tkによるプログラミング

2 I I / 61

R による統計解析入門

double float

joho09.ppt

GUI GUI Ruby GUI Ruby/Tk Ruby/Gtk GUI Ruby GUI

Java Java Java Java Java 4 p * *** ***** *** * Unix p a,b,c,d 100,200,250,500 a*b = a*b+c = a*b+c*d = (a+b)*(c+d) = 225

2 1 Web Java Android Java 1.2 6) Java Java 7) 6) Java Java (Swing, JavaFX) (JDBC) 7) OS 1.3 Java Java

etrust Access Control etrust Access Control UNIX(Linux, Windows) 2

¥¤¥ó¥¿¡¼¥Í¥Ã¥È·×¬¤È¥Ç¡¼¥¿²òÀÏ Âè2²ó

Java学習教材

Microsoft Word - MetaFluor70取扱説明.doc

web06.dvi

BASICとVisual Basic

PYTHON 資料 電脳梁山泊烏賊塾 PYTHON 入門 ゲームプログラミング スプライトの衝突判定 スプライトの衝突判定 スプライトの衝突判定の例として インベーダーゲームのコードを 下記に示す PYTHON3 #coding: utf-8 import pygame from pygame.lo


num2.dvi

2 R : R R [ 1.1] [ 2.1] R R R plot() contour() 2

( ) 1 Windows HTML ( ) ( ) ( ) WWW 10 ( )

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

2 A I / 58

RHEA key

r1.dvi

Excel ではじめる数値解析 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 初版 1 刷発行時のものです.

コンピュータ概論

piyo0704b.rtfd

TreeDrawer Application TreeDrawer File New( command+n) 2

N88 BASIC 0.3 C: My Documents 0.6: 0.3: (R) (G) : enterreturn : (F) BA- SIC.bas 0.8: (V) 0.9: 0.5:

1.ppt

OpenCV IS Report No Report Medical Information System Labratry

Python Speed Learning

1 1 2 Unix SVG SVG SVG SVG

(1/2) 2/45 HPC top runner application programmer PC-9801F N88-BASIC Quick BASIC + DOS ( ) BCB Windows Percolation, Event-driven MD ActionScript Flash

はじめに

technews2012autumn

HABOC manual


Transcription:

2008 1 Python GUI Tkinter PIL Python Microsoft Office Word PowerPoint USB PC CPU LAN Microsoft Office 1. 2. 3. 4. GUI (Graphic User Interface) 5. 6. LAN 7. CPU 8. Linux, Windows, MAC C GUI X window C Microsoft Basic JAVA Tcl/Tk Linux, Windows, MAC type miss Python ; C Python Hello World. 5

2 Python GUI Tkinter PIL C #include <stdio.h> main() { int i; for(i=0;i<5;i++) { printf("hello World.\n"); } } Python #! /usr//bin/env python for i in range(0,5): print "Hello World." C 8 Python 3 ( ) Python Python C C CPU 1/2 1/3 Python Python Python 1 1 Windows MAC: Google Python GUI Tkinter GUI wxpython wx- Python wxpython Tkinter GUI MAC ubuntu: ubuntu Linux CDROM ubuntu ubuntu Linux Windows ubuntu 2 ( ) Windows ubuntu 2 Windows 30 G Python ubuntu Ubuntu Python Python (gnome-terminal) sudo apt-get install python sudo apt-get install python-tk wxpython

2008 3 Python Python C ( ) C ; { } for if while : def class : C Python i = Python Python ( ) "a = 1" a a +, -, * / + 1 Windows Pytho Python Python Linux python Windows Python 2.6 IDLE >>> Run Module Shell 1)

4 Python GUI Tkinter PIL >>> 2*3.14 6.2800000000000002 >>> a= abc >>> b= def >>> a+b abcdef >>> (1+1j)*(1-1j) (2+0j) >>> from math import * >>> log(10.0) 2.3025850929940459 2 from math import * 2) ( ), [ ] + >>> a=[1,2,3] >>> b=[4,5,6] >>> c=a+b >>> c [1, 2, 3, 4, 5, 6] >>> a.append(b) >>> a [1, 2, 3, [4, 5, 6]] c append b 1 [m:n] m 0 n-1 c >>> print c[1:4] [2, 3, 4] >>> print c[0] 1 help() >>> a=[[1,2,3],[4,5,6],[7,8,9]] >>> a [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> a[2][1] 8 0 0 Python range(0,5) [0, 1, 2, 3, 4] for i in range[0, 5] i 0, 1, 2, 3, 4 3) [ ] () >>> (a,b)=(1,2) >>> a 1 >>> b 2 >>> d=(a,b) >>> d[0] 1 >>> d[1] 2 2 Python

2008 5 1 d=(1,),d = 1,2,3 a,b,c = 1,2,3 3 4) { :,...} >>> d1={} # >>> d1={ a :1, b :2, c :3} >>> print d1[ a ], d1[ c ] 1 3 >>> d1.keys() [ a, c, b ] >>> d1.values() [1, 3, 2] pickle( ) shelve( ) a) pickle pickle A A1, A2 B B1, B2, B3 d d= A :[ A1, A2 ], B :[ B1, B2, B3 ] GUI pickle pickle import pickle d={ A :[ A1, A2 ], B :[ B1, B2, B3 ]} object = d file = open( picle.dic, w ) pickle.dump(object, file) file.close() picle.dic pickle import pickle file = open( filename, r ) object = pickle.load(file) d = object print d file.close() pickle shelve pickle ( ) b) shelve shelve pickle shelve

6 Python GUI Tkinter PIL import shelve dbase = shelve.open( filename ) object = [ A1, A2 ] dbase[ A ]=object dbase.close() dbase = shelve.open( filename ) object = [ B1, B2, B3 ] dbase[ B ]=object dbase.close() shelve import shelve dbase = shelve.open( filename, r ) object=dbase[ A ] print object # [ A1, A2 ] dbase.close() Python shelve import math, pickle, shelve ( ) 1 2 1) def ( 1,..., n): return return def pr(): print aaa pr() print bbb aaa bbb pr() aaa print bbb def pr(x): print x pr( abc ) pr(123) x abc 123 print,

2008 7 ( ) pr(x)pr (x) def pr(): print x x=3 pr() 3 def pr(x): x=x+1 print sub,x x=3 pr(x) print main,x sub 4 main 3 global x x x global def pr(): global x x=x+1 print sub,x x=3 pr() print main,x sub 4 main 4 def pr(x) 2) Tkinter GUI 3 a) * ( ) def fun(*arg): for i in arg: print i x = 1; y = 2; z = 3 fun(x, y, z) 1 2 3 b) GUI def fun(a,bg= white ): print a, bg =,bg fun(3) fun(5,bg= red ) 3 bg = white 5 bg = red c) 2 def fun(a,**b): print a,b fun(3) fun(5,bg= red ) 3 {} 5 { bg : red }

8 Python GUI Tkinter PIL 4 ( ) C ID1.name 1 ID1.addr ID1 Python class ID: def init (self, name, addr): self.name = name self.addr = addr ID1=ID(, ) print ID1.name print ID1.addr class () ( Tkinter ) : init self name addr self name addr 2 ID1=ID(, ) ID1 self init 2 2. >>> class ID:... def init (self, name, addr):... self.name = name... self.addr = addr... >>> ID1=ID(, ) >>> print ID1.name >>> print ID1.addr >>>

2008 9 pr() 1 self self init name addr pr() print name, addr class ID: def init (self, name, addr): self.name = name self.addr = addr def pr(self): print self.name, self.addr ID1=ID(, ) ID1.pr() >>> class ID:... def init (self, name, addr):... self.name = name... self.addr = addr... def pr(self):... print self.name, self.addr... >>> ID1=ID(, ) >>> ID1.pr() >>> ID2=ID1 >>> ID2.pr() >>> ID3=ID(, ) >>> ID3.pr() >>> ID2=ID1 ID3 ID #! /usr/bin/env python class ID: def init (self, name, addr): self.name = name self.addr = addr def pr(self): print self.name, self.addr if name == main : ID1=ID(, ) ID1.pr() 1 Python 2 euc-jp Windows Shift-Jis # -*- coding: cp932 -*- class # if.py ID.py Linux chmod +x ID.py ID.py Windows Python26 Run Module

10 Python GUI Tkinter PIL ID (job) IDJ ID IDJ ID IDJ #! /usr/bin/env python from ID import * class IDJ(ID): def init (self, job, *ext): self.job=job ID. init (self, *ext) def pr(self): print self.job, self.name, self.addr if name == main : ID1=IDJ( MD,, ) ID1.pr() MD pr() IDJ from ID import * ID class IDJ(ID): ID IDJ init job, name,addr job *ext name, addr *ext job (self.job) ID. init (self, *ext) ID ID self.name, self.addr ext pr() ID print ID IDJ 1 1 Tkinter GUI 1 self 1 self ID pr() prname(x,y)

2008 11 class ID: def init (self, name, addr): self.name = name self.addr = addr def pr(self): print self.name,self.addr def prname(x,y): print x.name print y.name aaaa >>> a=id(, ) >>> b=id(, ) >>> ID.prname(a,b) >>> a.prname(b) a.xxx(b) append() def init () x-y 2 import math class Point: def init (self, x1, y1): self.x = x1 self.y = y1 # 2 def distance(p1, p2): dx = p1.x - p2.x dy = p1.y - p2.y return math.sqrt( dx * dx + dy * dy) >>> a=point(0,0) >>> b=point(1,1) >>> a.distance(b) 1.4142135623730951 2 Python sys, os, string, math >>> str(123) 123 a) 1 file=open( ID.py, r ) while 1: line=file.readline() if not line: break print line, line, print b) file=open( ID.py, r ) for line in file.readlines(): print line, a) : fn=open(fname,"w") fn.write(data) fn.close() b) euc fname= tmp.txt fn=open(fname, w ) for i in range(3): data=u \n data1=data.encode( euc_jp ) fn.write(data1) fn.close()

12 Python GUI Tkinter PIL fname= tmp.txt fn=open(fname, w ) for i in range(3): fn.write( u \n.encode( euc_jp )) fn.close() def echo(var): print var x=echo x( ) import sys for item in sys.argv: print item ( ) z=eval("2+3+4") print z 9 from math import * z=eval( sin(1.0) ) print z 0.841470984808 a) cmd= for i in range(3): print exec cmd 3 b) vi a.txt for i in range(3): print python execfile( a.txt ) 3 c) vi Ved3.py mainloop() #c.mainloop() execfile( Ved3.py ) + 3 3 Tkinter GUI

2008 13 GUI Tkinter Tkinter Tkinter Tc/Tk GUI (Tk) Python Tcl/Tk GUI GUI Tkinter Tcl/Tk $set = Tcl Tkinter Tcl/Tk on line Tkinter Linux Windows CTRL+C, CTRL+V Tcl/Tk GUI Tkinter Tcl/Tk Python Frame 10 2 10 Frame GUI 2 Tcl/Tk #!/usr/bin/env wish frame.f -bg "red" -bd 10 button.b -text " " -command goout pack.b -in.f pack.f -fill both -expand 1 proc goout {} { puts " " exit } Python Tcl/Tk python Python Tkinter import Tkinter as tk def goout(): print u exit() root=tk.tk() f=tk.frame(root,bg= red,bd=10) b=tk.button(f, text=u, command=goout) b.pack() f.pack(fill= both,expand=1) root.mainloop()

14 Python GUI Tkinter PIL 2 Windows # -*- coding: cp932 -*- import Tkinter tk root Tcl/Tk. Tcl/Tk button.b Python b=tk.button(root,...) root Tcl/Tk - Python = u Windows pack goout() Tcl/Tk Python mainloop Windows GUI GUI B.py File name: B.py import Tkinter as tk class B(tk.Frame): # def init (self, master=none): tk.frame. init (self, master) f=tk.frame(master,bg= red,bd=10) f.pack() b=tk.button(f,text=u, command=self.goout) b.pack() def goout(self): print u exit() if name == main : g=b() g.mainloop() g Frame f Button b goout class GIU import 3 class B tk.frame tk.frame tk.button init tk.frame tk.frame. init Frame tk.frame master master, self, ( ) 3 master None root GUI command=self.goout self goout goout

2008 15 class f, b self Frame GUI g=b() g g self b GUI pack mainloop goout import class if g=b() B init Frame Frame Button Frame Button command class B B g B mainloop B.py print class B.py GUI B.py extend File name: BE.py from B import * class BE(B): # def goout(self): print u extend exit() if name == main : g=be() g.mainloop() import.py Tkinter BE B B goout extend GUI B.py GUI

16 Python GUI Tkinter PIL BE2.py File name: BE2.py from B import * class BE(B): # def init (self, master=none): B. init (self, master) f=tk.frame(master,bg= green, bd=10) f.pack() l=b(f) l.pack() def goout(self): print u extend exit() if name == main : g=be() g.mainloop() 2a GUI 2 B extend GUI 2a 10 10 BE2.py BE.py class GUI BE2.py B. init GUI GUI 6 6 ( 3 ) 3 Frame 2 14 30 File name: Bus6.py import Tkinter as tk # class Frame(tk.Frame):

2008 17 # self. def init (self, var, master=none): self.var=var tk.frame. init (self, master) # f=tk.frame(master,bd=3,bg= red ) f.pack() # Label l = tk.label(f, text=self.var, relief=tk.ridge, bd=2) l.pack(side="left") for i in range(1,7): b=tk.button(f, text=i, command=self.make_it( self.var, i)) b.pack(side="left") # def make_it(self,side, i): def cmds(): print u %s %s % ( side,i) return cmds if name == main : fr=frame(u" ") fl=frame(u" ") fl.mainloop() 3 >>> 1 2 3 4 3 class Frame tk.frame tk.label tk.button init var self.var Frame None root init self l self.var text pack pack f Frame pack Frame text self.var 6 range for loop b make it 6 make it make it cmd make it return

18 Python GUI Tkinter PIL cmd side i command ( () ) Frame Frame Frame l b Bus6.py Bus6.py Bus6E.py extend File name: Bus6E.py from Bus6 import * # class FFrame(Frame): # def make_it(self,side, i): def cmds(): print u %s %s extend \ % (side,i) return cmds if name == main : fr=fframe(u" ") fl=fframe(u" ") fl.mainloop() print \ GUI config cget Frame bd=5, bg= green 2 4 4 config File name: Prototype.py import Tkinter as tk class Frame(tk.Frame): # # self. def init (self, var, master=none): self.var=var tk.frame. init (self, master) f=tk.frame(master,bd=5, bg= green ) f.pack() self.l = tk.label(f, text=self.var) self.l.pack(side="top") # def cget(self,data): return self.l.cget(data) def config(self,pos,data): self.l[pos]=data if name == main : l1 = Frame(u ) l2 = Frame(u )

2008 19 l1.config( bg, red ) print l1.cget( text ) l2.mainloop() init f self cget self config bg= red bg l1 l2 Frame config l1 l1 text cget init GUI class f, t, X sx, Y sy f 3 GUI 5 5 x y 1) Tcl/Tk Python import Tkinter as tk root=tk.tk() f=tk.frame(root, bg="red", relief="groove",borderwidth=3) t=tk.text(f,width=24, height=8, wrap=tk.none, setgrid=tk.true, font=( FixedSys, 14)) t.grid(column=0, row=0, sticky= nsew ) # X sx=tk.scrollbar(f,orient= horizontal, command=t.xview, width=10) t["xscrollcommand"]=sx.set sx.grid(column=0, row=1, sticky= ew ) # Y

20 Python GUI Tkinter PIL sy=tk.scrollbar(f,orient= vertical, command=t.yview, width=10) t["yscrollcommand"]=sy.set sy.grid(column=1, row=0, sticky= ns ) f.pack(fill=tk.both,expand=1) f.grid_columnconfigure(0,weight=1) f.grid_rowconfigure(0,weight=1) f.mainloop() Frame grid x y grid pack Python t.insert(tk.end, abc ) t.insert(tk.end, \n ) t.insert(1.0,u abc\n ) print t.get(1.0,tk.end) 1 0 t.delete(2.0,2.2) 2 0 2 2) class def init GUI root, self t GUI File name: TS.py import Tkinter as tk class TS(tk.Frame): # def init (self, master=none): tk.frame. init (self, master) f=tk.frame(master, bg="red", relief="groove",borderwidth=3) # Text self.t=tk.text(f,width=24, height=8, wrap=tk.none, setgrid=tk.true, font=( FixedSys, 14)) self.t.grid(column=0, row=0, sticky= nsew ) # X

2008 21 sx=tk.scrollbar(f, orient= horizontal, command=self.t.xview, width=10) self.t["xscrollcommand"]=sx.set sx.grid(column=0, row=1, sticky= ew ) # Y sy=tk.scrollbar(f, orient= vertical, command=self.t.yview, width=10) self.t["yscrollcommand"]=sy.set sy.grid(column=1, row=0, sticky= ns ) f.grid_columnconfigure(0, weight=1) f.grid_rowconfigure(0, weight=1) f.pack(fill=tk.both,expand=1) if name == main : t=ts() t.t.insert( 1.0,u \n ) print t.t.cget( bg ) t.t[ bg ]="green" t.t.delete( 1.0, 1.1 ) t.mainloop() grid TS tk.frame tk.text tk.scrollbar self cget, config insert, delete self t.t. t 8 24 FixedSys Windows True Type 14 Helvetica, Times from tkfont import * tkfont font1=font(family="helvetica", weight=normal, size=18) t.configure(font=font1) font1.configure(size=24) font1.configure(weight=bold) tkfont import TSE.py File name: TSE.py from TS import * from tkfont import * class TSE(TS): # def init (self, master=none): TS. init (self, master) font1=font(family="helvetica", weight=normal, size=8) self.t.configure(font=font1) if name == main : t=tse() t.t.insert( 1.0,

22 Python GUI Tkinter PIL u \n ) t.mainloop() tkfont import TS TSE self.t configure TSE TSE TS font1 self.t.configure t.insert mainloop GUI TSE GUI GUI pack GUI (fm.py) 1). Menubutton File name: fm.py import Tkinter as tk # def callback(): print exit exit() root=tk.tk() f=tk.frame(root,bg= red,bd=3) f.pack(anchor= nw ) file=tk.menubutton(f, text= File, relief=tk.raised) file.pack() file.m =tk.menu(file, tearoff=0 ) file[ menu ]=file.m file.m.add_separator() file.m.add_command(label= Quit, command=callback) f.mainloop() File Qiit Quit callback exit file file.m add Tcl/Tk Menubutton -menu file.m Tkinter file.m file file["menu"]=file.m Frame bg= red,bd=3 bd=0

2008 23 2) Tcl/Tk callback FM fm.py FM.py File name: FM.py import Tkinter as tk class FM(tk.Frame): # # self. def init (self, master=none): tk.frame. init (self, master) f=tk.frame(master,bg= red,bd=3) f.pack(anchor= nw ) file=tk.menubutton(f, text= File, relief=tk.raised) file.pack() file.m =tk.menu(file, tearoff=0) file[ menu ]=file.m file.m.add_separator() file.m.add_command(label= Quit, command=self.callback) # def callback(self): print exit exit() if name == main : f=fm() master=none g=tk.button(master,text=u, command=exit) g.pack(side= left ) f.mainloop() tk.frame root master self self FM File Menu 3) tkfiledialog >>> import tkfiledialog as D >>> dir(d) [ Dialog, Directory, Open, SaveAs, _Dialog, askdirectory, askopenfile, askopenfilename, askopenfilenames, askopenfiles, asksaveasfile, asksaveasfilename ] askopenfilename >>> f=d.askopenfilename >>> f=d.askopenfilename() >>> print f /home/tanaka/a1.py f File name: FM.py import Tkinter as tk import tkfiledialog as D # fname= noname.txt class FM(tk.Frame): # # self. def init (self, master=none): tk.frame. init (self, master) self.f=tk.frame(master,bg= red, bd=3)

24 Python GUI Tkinter PIL self.f.pack(anchor= nw ) file=tk.menubutton(self.f, text= File, relief=tk.raised) file.pack(side= left ) file.m =tk.menu(file, tearoff=0 ) file[ menu ]=file.m file.m.add_command(label= New, command=self.new_f) file.m.add_command(label= Open, command=self.open_f) file.m.add_command(label= Save, command=self.save_f) file.m.add_command( label= Save As, command=self.saveas_f) file.m.add_separator() file.m.add_command(label= Quit, command=self.exit_f) # def new_f(self): fname= noname.txt print FM,fname def open_f(self): global fname fname = D.askopenfilename( event=none) print FM,fname def save_f(self): print FM,fname def saveas_f(self): fname = D.asksaveasfilename( event=none) print FM,fname def exit_f(self): print exit_f exit() if name == main : f=fm() f.mainloop() pack New, Open, Save, Save As, Quit fname (New) noname.txt (Save Save As) FM.py FME.py FM.py FME.py callback FM.py Edit File FMJ.py extend File name: FME.py from FM import * class FME(FM): # def new_f(self): fname= noname.txt print extend FM,fname def open_f(self): global fname fname = D.askopenfilename( event=none) print extend FM,fname def save_f(self):

2008 25 print extend FM,fname def saveas_f(self): fname = D.asksaveasfilename( event=none) print extend FM,fname def exit_f(self): print extend exit_f exit() if name == main : f=fme() f.mainloop() from import File extend FME Tkinter TS FM Ed.py GUI FM FM.py FME.py Ed.py class Ed import GUI TS GUI 6 6 Ed.py FM TS File name: Ed.py from FM import * from TS import * import tkmessagebox as M # class Ed(FM): # def new_f(self): fname= noname.txt print extend FM,fname def open_f(self): global fname fname = D.askopenfilename( event=none) print extend FM,fname def save_f(self): print extend FM,fname def saveas_f(self): fname = D.asksaveasfilename( event=none) print extend FM,fname def exit_f(self): print extend exit_f exit()

26 Python GUI Tkinter PIL if name == main : master=none f=ed() t=ts() t.t.insert( 1.0,u \n ) f.mainloop() class Ed new f new f nonmae.txt def new_f(self): fname= noname.txt t.t.delete(1.0, end ) Ed.py New open f New Open def open_f(self): global fname fname = D.askopenfilename( event=none) fn=open(fname,"r") t.t.delete(1.0,tk.end) for line in fn.readlines(): t.t.insert(tk.end,line[:-1]. \ decode( euc_jp )+"\n") fn.close() save f fname def save_f(self): data=t.t.get(1.0,tk.end-1) data1=data.encode( euc_jp ) fn=open(fname,"w") fn.write(data1) fn.close saveas f def saveas_f(self): global fname fname = D.asksaveasfilename( event=none) data=t.t.get(1.0,tk.end) data1=data.encode( euc_jp ) fn=open(fname,"w") fn.write(data1) fn.close exit f tkmessagebox python >>> import tkmessagebox as M >>> dir(m) [ askokcancel, askquestion, askretrycancel, askyesno, showerror, showinfo, showwarning ] >>> askokcancel OK True, Cancel False exit f

2008 27 def exit_f(self): ans=m.askokcancel(u, u ) if ans==true: exit() else: return Ed.py Windows encode, decode shift jis / selection Linux Ctrl+C, Ctrl+X, Ctrl+V vi 2 // Tex Python

28 Python GUI Tkinter PIL (jpg, png, gif ) X-Y Tcl/Tk Tkinter bitmap, gif ImageTk import jpg, png 7 ImageTk.Photoimage jpg #! /usr/bin/env python import Tkinter as tk import Image as I import ImageTk as Itk c = tk.canvas(width=300, height=200) p=itk.photoimage(file= lena.jpg ) c.create_image(0,0,anchor=tk.nw, image=p) c.pack() c.mainloop() c lena.gif Itk.PhotoImage Tkinter c X-Y Image Python Imaging Library(PIL) ImageTk PIL Tkinter Frame #! /usr/bin/env python import Tkinter as tk import Image as I import ImageTk as Itk class C(tk.Frame): # def init (self, master=none): tk.frame. init (self, master) f=tk.frame(master,bg= red,bd=3) f.pack() self.c=tk.canvas(f,width=250, height=150) self.c.pack() if name == main : c=c() p=itk.photoimage(file= lena.jpg ) c.c.create_image(0, 0, anchor=tk.nw, image=p) c.mainloop() self 1)

2008 29 X-Y Photoimage get, put TS.py CA.py File name: CA.py import Tkinter as tk import Image as I import ImageTk as Itk class CA(tk.Frame): # def init (self, master=none): tk.frame. init (self, master) f=tk.frame(master, bg="red", relief="groove",borderwidth=3) # self.c=tk.canvas(f,width=250, height=150, scrollregion=(0,0,400,400)) self.c.grid(column=0, row=0, sticky= nsew ) # X sx=tk.scrollbar(f, orient= horizontal, command=self.c.xview,width=10) self.c["xscrollcommand"]=sx.set sx.grid(column=0, row=1, sticky= ew ) # Y sy=tk.scrollbar(f, orient= vertical, command=self.c.yview, width=10) self.c["yscrollcommand"]=sy.set sy.grid(column=1, row=0, sticky= ns ) f.grid_columnconfigure(0,weight=1) f.grid_rowconfigure(0,weight=1) f.pack(fill=tk.both,expand=1) # def cget(self,data): return self.c.cget(data) def config(self,pos,data): self.c[pos]=data def insert(self,pos,data): self.c.insert(pos,data) def get(self,pos1,pos2): return self.c.get(pos1,pos2) def delete(self,pos1,pos2): return self.c.delete(pos1,pos2) if name == main : c=ca() p=itk.photoimage(file= lena.jpg ) c.c.create_image(0, 0, anchor=tk.nw, image=p) c.c.create_line(0,0,60,30, tags="t1") c.mainloop() 8 8 CA.py TS.py 2) FM.py import Ed.py Ied1.py Ed.py Ied1 1 Ied.py

30 Python GUI Tkinter PIL File name: Ied1.py from FM import * from CA import * import tkmessagebox as M # class Ied(FM): # def new_f(self): fname= noname.txt t.t.delete(1.0, end ) def open_f(self): global fname fname = D.askopenfilename( event=none) fn=open(fname,"r") t.t.delete(1.0,tk.end) for line in fn.readlines(): t.t.insert(tk.end,line[:-1]. \ decode( euc_jp )+"\n") fn.close() def save_f(self): data=t.t.get(1.0,tk.end-1) data1=data.encode( euc_jp ) fn=open(fname,"w") fn.write(data1) fn.close def saveas_f(self): global fname fname = D.asksaveasfilename( event=none) data=t.t.get(1.0,tk.end) data1=data.encode( euc_jp ) fn=open(fname,"w") fn.write(data1) fn.close def exit_f(self): ans=m.askokcancel(u, u ) if ans==true: exit() else: return if name == main : f=ied() c=ca() p=itk.photoimage(file= lena.jpg ) c.c.create_image(0, 0, anchor=tk.nw, image=p) c.c.create_line(0,0,60,30,tags="t1") f.mainloop() Ied1.py import class Ed.py (new f) find all delete def new_f(self): fname= noname.txt for i in c.c.find_all() : c.c.delete(i) (open f) (0,0) def open_f(self): global fname fname = D.askopenfilename( event=none) self.p=itk.photoimage(file=fname) c.c.create_image(0,0, anchor=tk.nw, image=self.p, tags= latest ) latest Itk.PhotoImage p self create image (save f) Tkinter

2008 31 Postscript(PS) def save_f(self): c.c.postscript(file= a.ps ) PIL ps (PIL 1.16) (saveas f) def saveas_f(self): global fname fname = D.asksaveasfilename( event=none) c.c.postscript(file=fname) fname self (exit f) Ied2.py File name: Ied2.py from FM import * from CA import * import tkmessagebox as M # class Ied(FM): # def new_f(self): fname= noname.txt for i in c.c.find_all() : c.c.delete(i) def open_f(self): global fname fname = D.askopenfilename( event=none) self.p=itk.photoimage(file=fname) c.c.create_image(0,0, anchor=tk.nw, image=self.p, tags= latest ) def save_f(self): c.c.postscript(file= a.ps ) def saveas_f(self): global fname fname = D.asksaveasfilename( event=none) c.c.postscript(file=fname) def exit_f(self): ans=m.askokcancel(u, u ) if ans==true: exit() else: return if name == main : master=none f1=tk.frame(master,bg= green,bd=3) f1.pack(anchor= nw ) f=iedd(f1) c=ca() c.c.create_line(0,0,60,30,tags="t1") p=tk.photoimage(file= lena.gif ) c.c.create_image(50,0, anchor=tk.nw,image=p) f.mainloop() Tcl/Tk Tkinter python >>> from FM import * >>> from CA import * >>> c=ca() >>> dir(c.c) [ _Misc winfo_getint,...... ew_moveto, yview_scroll ] >>>

32 Python GUI Tkinter PIL PIL http://www.pythonware.com/library /index.htm (0,0) 1 x-y File name: pr xy.py import Tkinter as tk # B1 Motion def b1motion(event): print x =,event.x, \ y =, event.y c = tk.canvas(width=300, height=200) c.pack() c.bind( <B1-Motion>,b1motion) c.mainloop() b1motion event event X-Y event.x, event.y c bind File name: mv circle.py import Tkinter as tk # a1 def mv(event): data=c.coords( a1 ) x1,y1,x2,y2=data oldx=(x1+x2)/2.0 oldy= (y1+y2)/2.0 dx=event.x-oldx; dy=event.y-oldy c.move( a1,dx,dy) c = tk.canvas(width=300, height=200) c.pack() r1=c.create_oval(10, 10, 30, 30, fill= red, tag= a1 ) #c.bind( <B1-Motion>,mv) #c.bind( <Button-1>,mv) c.tag_bind( a1, <Button-1>,mv) c.tag_bind( a1, <B1-Motion>, mv, + ) c.mainloop() 20 (20,20) a1 <Button-1> <B1-Motion> mv mv move dx, dy event coords oldx, oldy (event) mv (#) c.bind mv c.tag bind

2008 33 mv 9 File name: mv circles.py import Tkinter as tk def mv(event): try: id=c.find( closest, event.x,event.y) tag,now=c.gettags(id) data=c.coords(tag) x1,y1,x2,y2=data oldx=(x1+x2)/2.0 oldy= (y1+y2)/2.0 dx=event.x-oldx; dy=event.y-oldy c.move(tag,dx,dy) finally: return c = tk.canvas(width=300, height=200) c.pack() x=10; y=30 for i in range(3): t= a +str(i) c.create_oval(x, x, y, y, fill= red, tag=t) x=x+20; y=x+20 c.bind( <B1-Motion>,mv) c.bind( <Button-1>,mv) c.mainloop() range(3) 3 a range x, y 20 mv find ID gettags ID 9 3 3 coords dx,dy move try/finally bind tag bind tag bind find bind Ied.py File name: Ied.py from FM import * from CA import * import tkmessagebox as M # class Ied(FM): # def new_f(self):

34 Python GUI Tkinter PIL fname= noname.txt for i in c.c.find_all() : c.c.delete(i) def open_f(self): global fname fname = D.askopenfilename( event=none) self.p=itk.photoimage(file=fname) c.c.create_image(0,0, anchor=tk.nw, image=self.p, tags= latest ) def save_f(self): c.c.postscript(file= a.ps ) def saveas_f(self): global fname fname = D.asksaveasfilename( event=none) c.c.postscript(file=fname) def exit_f(self): ans=m.askokcancel(u, u ) if ans==true: exit() else: return if name == main : # # def mv(event): try: id=c.c.find( closest,event.x, event.y) idn=id[0] c.c.tag_raise(idn) data=c.c.coords(idn) x1=data[0] y1=data[1] dx=event.x-x1; dy=event.y-y1 c.c.move(idn,dx,dy) finally: return def up(event): try: id=c.c.find( closest, event.x, event.y) idn=id[0] c.c.tag_raise(idn) finally: return f=ied() c=ca() c.c.create_line(0,0,60,30,tags="t1") p=itk.photoimage(file= lena.jpg ) c.c.create_image(50,0, anchor=tk.nw, image=p, tag= abc ) c.c.bind( <B1-Motion>,mv) c.c.bind( <Button-1>,mv) c.c.bind( <Button-3>,up) f.mainloop() import mv c.c.bind mainloopu() c.c.bind( <B1-Motion>, -,mv) c.c.bind( <Button-1>, -,mv) c.c.bind( <Button-3>, -,up) - mv try: ID coors x-y 4 2 x x1, y y1

2008 35 c.c.tag raise up mv 10 root # def top(): t1=tk.toplevel() t1.title( Toplevel ) w = tk.canvas(t1,width=150, height=100,bg= white ) w.pack() w.create_line(0,0,100,100) top 150, 100 (0,0,100,100) FM.py Frame Frame self.f=tk.frame(master,bg= red, bd=3) self.f.pack(anchor= nw ) file=tk.menubutton(self.f, text= File,relief=tk.RAISED) file.pack(side=tk.left) # Ied.py f=ied() b=tk.button(f.f,text= Top, command=top) b.pack(side=tk.left) c=ca() 10 Ied.py lena.gif lena.gif 11 Ied.py Frame f self self.f f file side=tk.left Top FM.py f.f pack 11 Tkinter, GUI

36 Python GUI Tkinter PIL

2008 37 12 1) 2) 3) X-Y 4) Ved1.py FM.py f self Ied.py Ved1.py File name: Ved1.py from FM import * from CA import * import tkmessagebox as M class Ved(FM): pass if name == main : master=none f=ved() b1=tk.button(f.f,text=u, command=exit) b1.pack(side= left ) b2=tk.button(f.f,text=u, command=exit) b2.pack(side= left ) b3=tk.button(f.f,text=u, command=exit) b3.pack(side= left ) c=ca() c.c.create_line(0,0,60,30, tags="t1") p=tk.photoimage(file= lena.gif ) c.c.create_image(50,0, anchor=tk.nw, image=p, tag= abc ) f.mainloop() 12 12 Ved1.py FM.py self FM.py Ved pass Python bd=0 3

38 Python GUI Tkinter PIL PhotoImag p p.width(), p.height() c.c[ width ]=x, c.c[ height ]=y pass class Ved(FM): # def new_f(self): self.fname= noname.txt for i in c.c.find_all() : c.c.delete(i) def open_f(self): for i in c.c.find_all() : c.c.delete(i) self.fname = D.askopenfilename( event=none) self.p=itk.photoimage( file=self.fname) c.c.create_image(0,0, anchor=tk.nw, image=self.p, tags= latest ) # x=self.p.width() y=self.p.height() # c.c[ width ]=x c.c[ height ]=y 1 2 Tcl/Tk Ved2.py import Tkinter as tk # def r_create(event): global sx,sy c.create_rectangle(event.x, event.y,event.x,event.y, outline= black,width=2, tags= rubbershape ) sx=event.x; sy=event.y def r_drag(event): global sx,sy,x2,y2 data=c.coords( rubbershape ) x1,y1,x2,y2=data x2=event.x; y2=event.y if (x2>sx) and (y2>sy): c.coords( rubbershape,sx,y1, x2,y2) else: c.coords( rubbershape,x2,y2, sx,sy) # def r_end(event): global sx,sy,x2,y2 print sx,sy,x2,y2 c.delete( rubbershape ) c = tk.canvas(width=300, height=200) c.pack() c.bind( <Button-1>, r_create) c.bind( <B1-Motion>, r_drag) c.bind( <ButtonRelease-1>, r_end) c.mainloop() 3 r create 2 rubbershape r drag rubbershape X-Y coords

2008 39 r end rubbershape Ved1.py Ved2.py new f open f Ved2.py if name == main : master=none f=ved() # # def r_create(event): global sx,sy # find_withtag c.c.delete( rubbershape ) c.c.create_rectangle(event.x, event.y,event.x, event.y, outline= black, width=2, tags= rubbershape ) sx=event.x; sy=event.y def r_drag(event): global sx,sy,x2,y2 data=c.c.coords( rubbershape ) x1,y1,x2,y2=data x2=event.x; y2=event.y if (x2>sx) and (y2>sy): c.c.coords( rubbershape, sx,y1,x2,y2) else: c.c.coords( rubbershape, x2,y2,sx,sy) # def trim_on(): c.c.bind( <Button-1>, r_create) c.c.bind( <B1-Motion>, r_drag) # def trim_off(): im=i.open(f.fname) x1,y1,x2,y2=c.c.coords( rubbershape ) im2=im.crop((int(x1),int(y1), int(x2),int(y2))) im2.show() b1=tk.button(f.f,text=u, command=trim_on) b1.pack(side= left ) b2=tk.button(f.f,text=u, command=trim_off) b2.pack(side= left ) b3=tk.button(f.f,text=u, command=exit) b3.pack(side= left ) c=ca() f.mainloop() PIL show() 13 13 Ved2.py File

40 Python GUI Tkinter PIL command c.create c.c.create coords (0,0) PIL im crop show() 2 crop tmp.jpg PIL f.fname tmp.gif fname self.f trim off p self trim off # def trim_off(): global p global maxx,maxy x1,y1,x2,y2=c.c.coords( rubbershape ) im=i.open(f.fname) im2=im.crop((int(x1),int(y1), int(x2),int(y2))) im3=im2.convert( RGB ) im3.save( tmp.gif ) for i in c.c.find_all() : c.c.delete(i) fname= tmp.gif p=itk.photoimage(file=fname) c.c.create_image(0, 0, anchor=tk.nw, image=p) maxx=p.width() maxy=p.height() c.c[ width ]=maxx c.c[ height ]=maxy c.c.bind( <Button-1>, -, r_create) c.c.bind( <B1-Motion>, -, r_drag) im2 RGB im3 tmp.jpg Tkinter PIL maxx, maxy open f GUI 14 14 15 I II III (X ) 3

2008 41 15 I II III Ved2.py Ved3.py 3 1 II III # def cur1_move(event): global old_cur1y c.c.move( cur1,0, event.y-old_cur1y) old_cur1y=event.y # def base(): global old_cur1y global maxx old_cur1y=5 c.c.create_rectangle(0,0,10,10, fill= green, tag= cur1 ) c.c.create_line(0,5,maxx,5, fill= green, width=2, tag= cur1 ) c.c.bind( <Button-1>, cur1_move) c.c.bind( <B1-Motion>, cur1_move) # def basei(): global old_cur1y,basei_y basei_y=old_cur1y def baseii(): global old_cur1y,baseii_y baseii_y=old_cur1y def baseiii(): global old_cur1y,baseiii_y baseiii_y=old_cur1y b1=tk.button(f.f,text=u, command=trim_on) b1.pack(side= left ) b2=tk.button(f.f,text=u, command=trim_off) b2.pack(side= left ) b3=tk.button(f.f,text=u, command=base) b3.pack(side= left ) b3=tk.button(f.f,text=u I, command=basei) b3.pack(side= left ) b3=tk.button(f.f,text=u II, command=baseii) b3.pack(side= left ) b3=tk.button(f.f,text=u III, command=baseiii) b3.pack(side= left ) b3=tk.button(f.f,text=u, command=exit) b3.pack(side= left ) c=ca() f.mainloop() base I basei I Y III b3

42 Python GUI Tkinter PIL base maxx Y old cur1y 5 (0,0,10,10) cur1 (0,5) (maxx,5) 2 cur1 1 cur1 move cur1 move move dx,dy, x,y old cur1y Y x dx 0 dy event.y cur1 old cur1y I, II, III Y basei, baseii, baseiii old cur1y 16 X-Y 16 Ved3.py I II III 1 I II III xv gimp Tkinter PhotoImage get put PIL PhotoImage p X-Y data=p._photoimage photo.get(x,y) data RGB X Y 3 Y 3

2008 43 Y if Y trace # def trace(): global AA,BB,CC t1=tk.toplevel() t1.title( Toplevel ) w = tk.canvas(t1,width=maxx, height=maxy,bg= white ) w.pack() sep=maxy/3 sep2=2*sep c.c.create_line(1,0,1,maxy, fill= green,tag= cursor ) curx=0 AA=[]; BB=[]; CC=[] for i in range(maxx): AA.append(0); BB.append(0) CC.append(0) # x for i in range(maxx): # curdx=i-curx c.c.move( cursor,curdx,0) curx=i c.c.update() # y A=[]; B=[]; C=[] c.c.coords( cursor,i,0,i,maxy) for j in range(maxy): data=p._photoimage photo.get( i, j) r=string.split(data, ) x=int(r[0]) if x< 50: if j<sep : A.append(j) elif j<sep2 : B.append(j) else: C.append(j) # AA An=len(A) sum=0 if An!=0 : for k in range(an): sum=sum+a[k] AA[i]=sum/An # BB Bn=len(B) sum=0 if Bn!=0 : for k in range(bn): sum=sum+b[k] BB[i]=sum/Bn # CC Cn=len(C) sum=0 if Cn!=0 : for k in range(cn): sum=sum+c[k] CC[i]=sum/Cn if i>0: w.create_line(i-1,aa[i-1],i, AA[i], width=2) w.create_line(i-1,bb[i-1],i, BB[i], width=2) w.create_line(i-1,cc[i-1],i, CC[i], width=2) Y X AA, BB, CC I, II, III Y Y sep sep2 AA, BB,CC 0 X i maxx for Y Y j maxy for A, B, C

44 Python GUI Tkinter PIL 50 Y A, B, C Y j A, B, C AA, BB, CC Y if 1msec 0 1 trace f1 string import b3=tk.button(f.f,text=u, command=exit) b3.pack(side= left ) f1=tk.frame(master,bg= red,bd=3) f1.pack(anchor= nw ) b3=tk.button(f1,text=u, command=trace) b3.pack(side= left ) c=ca() f.mainloop() 17 III 17 get, put Python from Tkinter import * c = Canvas(width=128, height=128) p=photoimage(file= lena.gif ) c.create_image(0,0,anchor=nw,image=p) c.pack() p.put("#ff0000", to=(0,0,30,30)) # (29,0) p.get(29,0) u 255 0 0 <- p.get(30,0) <- u 201 128 102 c gif PhotoImage (0,0) (29,29)

2008 45 RGB 16 # RGB r, g, b color= #%02x%02x%02x % (r,g,b) p.put(color, to=(0,0,30,30)) r, g, b import string data=p.get(29,0) r=string.split(data, ) int(r[0]) 255 <- 18 18 get, put PhotoImage picel GIF Tkinter PhotoImage PIL data=p._photoimage photo.get(x,y) r=string.split(data, ) II Python R (-) BB AA (-) II (+) I F (+) (+) CC III (-) L 19 19 f(x, y, z) 2 II I III II second Ved3.py Ved4.py second second

46 Python GUI Tkinter PIL I II AA CC Y # II # II I # III def second(): global AA,BB,CC,SdII global di,dii,diii,sdii global basei_y,baseii_y,baseiii_y c.c.delete( cursor ) c.c.create_line(1,0,1,maxy, fill= green,tag= cursor ) curx=0 t2=tk.toplevel() t2.title( II Image ) w2 = tk.canvas(t2,width=250, height=250,bg= white ) w2.pack() di=[]; dii=[]; diii=[]; SdII=[] for i in range(maxx): # curdx=i-curx c.c.move( cursor,curdx,0) curx=i c.after(1) c.c.update() di.append(basei_y-aa[i]) dii.append(basei_y-bb[i]) diii.append(basei_y-cc[i]) SdII.append(-(dI[i]+dIII[i]) -250) if i>0: w2.create_line(i-1,sdii[i-1], i,sdii[i],width=2) II c=ca() b3=tk.button(f1,text=u II, command=second) b3.pack(side= left ) c=ca() f.mainloop() 20 II Ved4.py Ved5.py 3 2 20 II I III II X Y di dii axis # def axis(): global di,dii,diii,sdii global dx,dy c.c.delete( cursor ) c.c.create_line(1,0,1,maxy, fill= green,tag= cursor ) curx=0 t3=tk.toplevel() t3.title( Axis ) w3 = tk.canvas(t3,width=250, height=250,bg= white ) w3.pack() dx=[]; dy=[] for i in range(maxx): # curdx=i-curx c.c.move( cursor,curdx,0)

2008 47 curx=i c.after(100) c.c.update() dx.append((di[i]+0.5*dii[i]) +150) dy.append((dii[i]*0.866)+250) if i>0: w3.create_line(dx[i-1], dy[i-1], dx[i],dy[i], width=2) b3=tk.button(f1,text=u, command=axis) b3.pack(side= left ) c=ca() f.mainloop() 21 X-Y 21 II

48 Python GUI Tkinter PIL launcher) ( 22) GUI Python Tkinter wm (launcher.py) import Tkinter as tk import os def vi(): os.system( kterm -e vi vicmds & ) def calc(): os.system( calc.py & ) def phone(): os.system( phone.py & ) root=tk.tk() root.title( launcher ) root.wm_geometry( +0+0 ) f=tk.frame(root, bd=2,bg= red ) f.pack(side= left ) b = tk.button(f,text= vicmds, command=vi) b.pack(side= left ) b = tk.button(f,text= calc, command=calc) b.pack(side= left ) b = tk.button(f,text= phone, command=phone) b.pack(side= left ) f.mainloop() GUI 3 wm geometry Display GUI Tk() root 22 Display vi Python os.system vi Kterm( ) vi vi vicmds -e & (calc.py) Entry 2 23 GUI calc.py import Tkinter as tk import os from math import * def cmd(event): data=eval(e1.get()) e2.delete(0, end ) e2.insert(tk.end,data)

2008 49 root=tk.tk() root.title( calc ) f=tk.frame(root, bd=2,bg= yellow ) f.pack() e1 = tk.entry(f) e1.pack() e1.bind("<return>",cmd) e2 = tk.entry(f) e2.pack() f.mainloop() Text Entry 1 insert delete <Return> cmd e1 e2 import Tkinter as tk import commands from TS import * from math import * def cmd(event): global data,dbta,a data=e1.get() dbta= grep +data+./nenga/n04.txt a=commands.getstatusoutput( dbta.encode( euc_jp )) t.t.delete(1.0,tk.end) t.t.insert( 1.0,a[1].decode( euc_jp )) root=tk.tk() root.title( phone ) f=tk.frame() f.pack() l1=tk.label(f,text=u ) l1.pack(side= left ) e1 = tk.entry(f) e1.pack(side= left ) e1.bind("<return>",cmd) t=ts() (phone.py) pickle shelve text grep vi uniq, sort cut, paste unix GUI 1 phone.py 24 GUI TS() TS() cmd cmd grep Python unix

50 Python GUI Tkinter PIL commands getstatusoutput 1 grep./nenga/n04.tx euc encode a euc decode insert 4 30 8K byte HITAC-10 Assembler Fortran C X11R4 CPU Tcl/Tk Tcl/Tk jpg png Python+PIL Python C++ C# JAVA Python Python 4 2009 Tcl/Tk 1. Python 2001. 2. Mark Lutz, David Ascher Python. O Reilly, 2000. 3. tcl/tk. 1997. 4. http://kansai.anesth.or.jp/gijutu/ python/howto-python.php

init........ 8 init............ 14 main............ 9 name............ 9 add............ 22 add command........ 22 add separator........ 22 append.... 4, 11, 43 argv................ 12 askdirectory........ 23 askokcancel........ 26 askopenfile............ 23 askopenfilename........ 23 askopenfilenames........ 23 askopenfiles........ 23 askquestion........ 26 askretrycancel........ 26 asksaveasfile........ 23 asksaveasfilename.... 23 askyesno............ 26 B1-Motion............ 32 Basic................ 1 bitmap............ 28 borderwidth........ 19 break............ 11 cget........ 18, 19, 21 class................ 8 class............ 3 close................ 11 column............ 19 config.... 18, 19, 21 coords........ 33, 40 crop................ 40 decode.... 26, 27, 50 def................ 3 delete............ 21 delete............ 30 dump................ 5 encode.... 12, 27, 50 Entry............ 48 euc-jp................ 9 eval................ 12 event................ 32 ew................ 19 exec................ 12 exit f............ 26 finally............ 33 find................ 33 FixedSys........ 19, 21 for................ 3 import............ 14 Frame............ 13 Frame........ 14 from................ 4 get................ 29 getstatusoutput........ 50 gif................ 28 global................ 7 grep................ 49 grid................ 21 grid............ 20 grid columnconfigure.... 19 grid rowconfigure........ 19 groove............ 19 GUI................ 1 height........ 19, 38 Helvetica............ 21 horizontal............ 19 if................ 3 Image........ 28 ImageTk............ 28 import........ 4, 28 insert........ 21, 50 Itk.PhotoImage........ 28 JAVA................ 1 jpg................ 28 keys................ 5 launcher............ 48 Linux................ 1 load................ 5 MAC................ 1 mainloop............ 14 master............ 14 math................ 4 Menubutton........ 22 move................ 33 new f............ 26 None................ 14 ns................ 19 nsew................ 19 open................ 11 open f............ 26 orient............ 19 os.system............ 48 pack............ 22 pass................ 37 pickle................ 5 PIL................ 28 png................ 28 Postscript............ 31 print.... 2, 4, 5, 11 printf................ 2 PS................ 31 put................ 29 Python Imaging Library 28 range........ 17, 33 readline............ 11 readlines............ 11 relief................ 19 Return............ 49 return................ 6 RGB................ 40 root................ 14 row................ 19 save f............ 26 saveas f........ 26 selection........ 27 self............ 8, 14 setgrid............ 19 shelve................ 5 shift jis............ 27 show................ 39 showerror............ 26 showinfo............ 26 sticky............ 19 str............ 11, 33 sys................ 12 Tcl/Tk............ 1 Times............ 21 tk.button............ 14 tk.frame............ 14 tk.frame. init........ 14 tk.label............ 17 tk.menu............ 22 tk.menubutton........ 22 tk.none............ 19 tk.scrollbar........ 21 tk.text............ 21 tk.true............ 19 tkfiledialog........ 23 tkfont............ 21 Tkinter........ 13, 28 tkmessagebox........ 26 True Type............ 21 try................ 33 ubuntu............ 2 unix............ 49 values................ 5 vertical............ 19 vi................ 48 weight............ 19 while............ 3 width........ 19, 38 Windows............ 1 wm............ 48 wm geometry........ 48 wrap................ 19 write................ 11 xscrollcommand........ 19 yscrollcommand........ 19............ 4........ 14............ 44............ 29............ 8........ 8............ 2........ 2............ 3............ 10............ 15........ 3, 8 51

52 Python GUI Tkinter PIL........ 12................ 11................ 6........ 28............ 30............ 30........ 7, 10............ 3, 6............ 12........ 12........ 6........ 7............ 6............ 3, 8............ 8........ 10............ 8........ 44............ 6............ 10, 15................ 8........ 12............ 13............ 2............ 21............ 48................ 5................ 3................ 11........ 10.... 19........ 19........ 13, 19................ 3................ 33.... 3, 10, 15, 23............ 4, 7............ 3................ 5................ 3.... 19........ 25........ 7................ 12............ 48........ 35............ 38............ 18............ 38............ 4............ 4................ 4........ 32............ 5............ 9................ 6............ 44............ 11.... 12............ 21................ 3............ 30........ 22............ 3................ 8............ 4............ 13................ 5............ 4............ 21........ 4, 8, 15............ 9............ 13............ 3, 11........ 12............ 14........ 38............ 13............ 48................ 4............ 4............ 4................ 2............ 8............ 5