Python Essential ??? - PowerPoint PPT Presentation

About This Presentation
Title:

Python Essential ???

Description:

2001. 4. 25( ) Python Essential Gui - Tkinter : – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 13
Provided by: 4518
Category:

less

Transcript and Presenter's Notes

Title: Python Essential ???


1
Python Essential ???
2001. 4. 25(?)
  • Gui ????? - Tkinter

??? ???
2
? Tkinter
  • Tkinter ??( Tkinterface)? Tk GUI toolkit? ????
    ?? ?
  • ?? ???????.
  • Tk ? Tkinter? Linux/Unix , Windows, Macintosh ??
    ????
  • import Tkinter ?? from Tkinter from
  • ??? ?????? ??
  • rootTk()
  • Tkinter? ????? ??? Tk root??? ???? ??. root
  • ??? ?? ?? ????? ?? ? ????? ? ? ?? ?
  • ?? ? ??.
  • w Label(root, text"Hello, world!")
  • w.pack()
  • Label ??? ???, ??? ?? ??? ?? ??? ? ??.
  • ???? ???? ??? text ??? ????. ???, pack()
  • ? ?????, ??? ???? ?? ??? ???? ? ?
  • ?? ??? ?? ???.

Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
3
? ?? Widget ??
Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
  • from Tkinter import rootTk()   
  •                    root.mainloop()
                 .
  • ?? ??
  • rootTk()
  • ??? widget? ???.
  •   root.mainloop()
  • ? ????? ???? ?? ? ?? ??? ??? ???. ???
  • ?????? ?? ??????? ???? ???? ??(?????
  • ????? ????).  root ???? pack?? ??? ?????
  • ???????

????
4
? PUSH button
from Tkinter import class App  def
__init__(self, master)    frame
Frame(master)   frame.pack()
???? ??? ??.    self.button Button(frame,
text"QUIT", fg"red", commandframe.quit)   self
.button.pack(sideLEFT)    self.w
Button(frame, text"Hello", commandself.say_hi) 
  self.w.pack() def say_hi(self)   print
"hi there, everyone!" root Tk() app
App(root) root.mainloop()
Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
?? ??
Hello ?????
5
? RADIO button(1)
from Tkinter import class App     def
__init__(self, master)          frame
Frame(master)          frame.pack()       
  MODES ("Monochrome", "1"), ("Grayscale",
"L"), ("True color", "RGB"), ("Color separation",
"CMYK")   ??? ?? ??         self.v
StringVar()         self.v.set("L") ???
??         for text, mode in MODES MODES? ???
????? ?? b Radiobutton(frame,
texttext, variableself.v, valuemode,
commandself.rb)    b.pack(anchorW,
fill'x') fill'x' ??? x? ??? ???    
 self.w Label(master, textself.v.get())   
    self.w.pack()     def rb(self)      
 self.w.configure(textself.v.get())   root
Tk() app App(root) root.mainloop()
Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
6
? RADIO button(2)
Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
  • ????
  • ??? ???? ??? (??? ???, ?? ?)
  • MODES ("Monochrome", "1"),   ("Grayscale",
    "L"),   ("True color", "RGB"),    ("Color
    separation", "CMYK")  
  • ?? ?? ?? ??? ???? ? ??? ????? ? ??? ??
    ?? ??? ???(MODES)? ???. ????? ??? ????.
    ???? ??? ??(v)? ???? ??? ???? ??? ?? ??? ?????
    ??. ?? ?? v.set('L') ????.

????

If gt b Radiobutton(indicatoron0,
texttext,variableself.v, valuemode,commandself
.rb)   
7
? Packer ?? ??
  • Packer
  • '?? ?? ?? ?? ????, ??? ???? ??? ???? ????
  • ?? ???.
  • ????
  • from Tkinter import
  • root Tk()
  •   widget1 Button(root, text"Widget1")
  • widget2 Button(root, text"Widget2")
  • widget3 Button(root, text"Widget3")
  •   widget1.pack(sideLEFT)
  • widget2.pack(sideLEFT)
  • widget3.pack(sideLEFT)
  •   root.mainloop()

Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????


????
  • If gt widget1.pack(sideTOP)
  • widget2.pack(sideTOP)
  • widget3.pack(sideTOP)

8
? Widget ??/???
  • Widget ??
  • ?? ????? ??? ??? ??? ?? after? ??
  • ex) widget1.pack(afterwidget)
  • ?? ???? ??? ??? ??? ?? before? ??
  • ex) widget1.pack(beforewidget)

Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
  • Widget ???
  • pack method? ???? fillX, fillY ? ???? ? ?? ????
    ????
  • ???? ???.

Widget ?? ????
Widget ??? ????
9
? ???? ???(1)
from Tkinter import def print_msg(msg)   w.co
nfigure(textmsg)def menu_new(eventNone)   pr
int_msg("New called")def menu_open(eventNone)
   print_msg("Open called")def
menu_about(eventNone)   print_msg("About
called")def menu_exit(eventNone)   root.quit
()   root.destroy()rootTk()creat
menumenuMenu(root)                         
??? ??? ??.menu? ????? filemenuroot.config(menum
enu)                root?? menu ??? ????.
Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
10
? ???? ???(2)
Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
wLabel(root, text"Hello world!", width50,
height3)    ????? ??? Label ??.w.pack()fileme
nuMenu(menu)              menu? ??? ?? ??? ??
?? filemenu? ???.menu.add_cascade(label"File",
menufilemenu)         menu ??? filemenu?
????.filemenu.add_command(label"New",underline0
,accelerator"CtrlN",commandmenu_new)         
         ????
??.filemenu.add_command(label"Open",underline0,
accelerator"CtrlO",commandmenu_open)filemenu.a
dd_separator()          ??? ?????.filemenu.add_c
ommand(label"Exit",underline1,accelerator"Altx
,commandmenu_exit)helpmenuMenu(menu)
          menu? ??? ?? ??? ?? ?? helpmenu?
???.menu.add_cascade(label"Help",
menuhelpmenu)helpmenu.add_command(label"About",
commandmenu_about)root.bind("ltControl-ngt",menu
_new)root.bind("ltControl-ogt",menu_open)root.bind
("ltAlt-Key-xgt",menu_exit)root.mainloop()
11
? Event and Bindings
  • ?? ??? bind ???? ???? ???? ???? ???
  • ?? ?? ? ??. ?? event? ???? ???? ???? ha
  • ndler? ????.
  • ??) widget.bind(event.handler)

Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
  • Event? ??
  • ltButton-1gt ?????? ?? ??? ???. 1? ??, 2? ???,
    3? ??? ????.
  • ltB1-Motiongt ??? 1? ????? ???? ????.
  • ltEntergt ??? ???? ?? ??? ????.
  • ltLeavegt ??? ???? ??? ????.
  • ltShift-Upgt ???? ????? ?? ???? ?? ??? ???
    ???.
  • ltConfiguregt ??? ??? ???. ??? ??? ??? event???
    width,height ???
  • ????.
  • Event? ??
  • ltWidgetgt ???? ???? ??. ??? ?? Tkinter ??
    ??????.
  • ltx,ygt ?? ???? ??
  • ltchargt ???? ????? ??
  • ltkeysymgt ? ??
  • ltkeycodegt ? ??
  • ltwidth,heightgt ??? ??? ??(??)

12
? ???? ? ???
Tkinter ?? widget?? Push button Radio
button Packer ???? Widget ?? ???? ??? ????
??? ????
  • Programming Python 2nd Edition
  • (Mark Lutz, OREILLY)
  • -http//www.pythonware.com/library/tkinter
  • /introduction/index.htm
  • Teach your self Python in 24 hours
  • (SAMS)
Write a Comment
User Comments (0)
About PowerShow.com