tkinter高清文档

5星(超过95%的资源)
所需积分/C币:29 2017-12-04 00:02:55 760KB PDF
295
收藏 收藏
举报

python的tkinter文档,内容高清,涵盖知识完整,非常推荐
Review Copy. Do not redistribute! 1999-12-01 22: 15 17. The Canvas Oval Item Manager Methods…… Methods Options Options… 28. The intyar class 18. The Canvas Polygon Item…… When to use the IntVar class Methods Patterns Options… 19. The Canvas Rectangle Item 29. The Labcl widget… Methods 66 When to use the label widget. Opt 66 Patterns 20. The Canvas Text Item Method Methods 67 Options 30 The LisTbox widgeT …93 21. The Canvas Window item When to use Methods Pa Methods 6 2. The Checkbutton widget ………70 SelectionMethods. When to use the Checkbutton widget Patterns Methods 31. The Menu widget.…… O When to use the Menu widget............... Patte When to use the Double var Class Methods Palle Displaying Menus Methods When to use the Entry widget When to use the Menubutton widget 07 Concepts Patterns Indexes Methods 107 Patterns Mcthods 33. The Message widget ,108 Selection methods When to use the Message widget Scrolling Methods Patterns Methods 25. The Font Class Pallens 34. The Pack Geometry Manager... When to use the Pack Manager... 110 Fuinctions Patterns ptions… Methods 26. The Frame Widget Widget M When to use the frame Widget. Manager method Patterns ptions When to use the PhotoImage Class 112 27. The Grid Geometry Manager Patterns When to use the grid Manager Methods Patte Mel lods The Place Geomel ry Manager Widget Methods....... When to use the Place Manager Copyright(c)1999 by Fredrik Lundh Review Copy. Do not redistribute! 1999-12-01 22: 15 Patte Methods Options…… tag get …142 37 The Radiobutton widget 18 tag_bind ………142 When to use the Radiobutton widget. tag unbind 142 Patte tag names …………………142 Methods… 审 11q tag extrange…,,,,,… Options… tag prevrange…,,,… 38. The Scale widget… tag lower :. 143 When to use the Scale widget....... tag raise Palle l ag_ranges Mel hnds Melhods for selections 143 9. The Scrollbar widget.… Options… Methods for rende bb When to use the Scrollbar widget.....,…,… 125 dlineinfo 144 Patterns Methods for Printing.......…………144 Methods Methods for Searching ……144 Option scarch The str Mcthods for scrollin When to use the string var class 129 scan mark, scan dragto.......... 145 Pattern 145 When to use the Text widget ckplace…… Concepts Options Indexes 42. The Toplevel widget When to use the Toplevel widget……… Line endings………… Methods amed indexes Options Coordinates Basic widget Mcthods ………………………………………………………151 Embedded objects Configuration 151 Marks get …151 Pallens …135 kevs …15l Methods Event processing ……452 Methods for marks 38 mainloop …152 Methods for embedded windows Methods for Embedded Images update Image create lmage cnet,“,…… …152 focus displayot …152 focus for for Methods for Tags ..... tk focus Next Ik locust Copyright(c)1999 by Fredrik Lundh Review Copy. Do not redistribute! 1999-12-01 22: 15 grab_rele winfo screenvisual grab_set 153 winfo_toplevel grab_set_ global …159 ab ………153 wait variable… ………………153 Miscellaneous wait bell… 999 I append…… … Event callbacks… 154 clipboard clear bind 154 lection clear unbind selection_get bind al unbind all 154 Seleclion nwrl bind class selection_own_get unbind class tk focus follows Mouse bindtags…… …155 tk strict Motif …160 bindtags Alarm handlers and other non-event callbacks Lkinter interface methods after cancel 161 after idle 55 register Window management vinto atom Ifo atonal Window Related Information winfo cells option_clear winfo children… option get …161 winto clas ption_readfile... winfo containing ......................... 156 Visibility mcthods...... 16:::::: winfo_ _ depth 157 deiconif 162 winfo exists winfo pixels withdraw winfo_ geometry …157 state 62 winfo_width, winfo_height SIvle mellors t winfo_ snapped group… -++ winfo name winfo parent indow Geometry Methods. winto p 163 winfo rcqhcight, winfo rcqwidth.. geomety winfo_root, winfo rooty aspect,…,,, 58 max winfo screencells nmInsIZ 103 winfo_ screendepth…. resizable winfo screenwidth, winfo screenheighl Tcon Melhods fo screenmmwidth, winfo screenmmheigh Copyright(c)1999 by Fredrik Lundh Review Copy. Do not redistribute! 1999-12-01 22: 15 iconmask Iconname composition………… ……164 Property Access Methods ……164 colormapwindows... 165 fr pr 666 5 Inde 166 Copyright(c)1999 by Fredrik Lundh Review Copy. Do not redistribute! 1999-12-01 22: 15 Preface This is yet another snapshot of my continously growing Tkinter documentation. I. Introducing Tkinter If you like this book, you might be interested in hearing that O Reilly Associates The first few chapters in this book provide a brief introduction to Tkinter. After reading this hllp://www.ora.com]willbepublishingaTkinlerbook(tenlalivelycalledProgramming you should have a fair grasp of the Tkinter fundamentals Tkinler in Python)in a not loo dislanl fulure. This book fealures lols of brand new malerial written by yours truly, giving you a more thorough description of Tkinter(and many other things)than you can find anywhere else Cast update: Oct o5, 1999) Copyright(c)1999 by Fredrik Lundh Review Copy. Do not redistribute! 1999-12-01 22: 15 Chapter 1. What's Tkinter? Chapter 2, Hello, Tkinter The Tkinter module(Tk interface")is the standard Python interface to the tk gui toolkit But enough talk Time to look at some code instead fromScriptics(http://www.scriptics.com)(formerlydevelopedbySunLabs) you know, every serious tutorial should start with a"hello world-type example. In this oih Tk and Tkinler are available on nosl Unix platforMs, as well as nn Windows and overview, we 'll show you nol only one such example, bul Iwn Macinlosh syslems. Starling wilh Ihe 8.0 release, Tk offers native look and feel on all First, let's look at a pretty minimal version rkinter consists of a number of modules. The 'fk interface is located in a binary module named Example 2-1. Our Firsl Tkinler PrograIn tkinter(this was tkinter in earlier versions). This module contains the low-level interface to Tk, and should never be used directly by application programmers. It is usually a shared library File: hello.py Cor DLL), but might in some cases be statically linked with the Python interpreter from tkinter im port x most important modules are the Tkinter module itself, and a module called Tkconstants The 3 In addilion lo Ihe: Tk inler face module, Tkinler includes a numberof Pylhon modules. The Iw root Tko former automatically imports the latter, so to use Tkinter, all you need to do is to import one module W= Label(root, text=Hello, world! " wpack() import Tkinter root. rmainIoopo Or more often from tkinter n。ort* Running the Example To run the program, run the script as usual: 车 python hello1.py The following window appears Figure 2-1. Running the program Helbo, world To stop the program, just closc the window. Details We start by importing the Tkinter module. It contains all classes, functions and other thing needed to work with the Tk toolkit. In most cases, you can simply import everything from Tkinter into your module' s namespace from Tkinter im port x Copyright(c)1999 by Fredrik Lundh Review Copy. Do not redistribute! 1999-12-01 22: 15 Chapter 2. Hello, Tkinter To initialize Tkinter, we have to create a Tk root widget. This is an ordinary window, with a title bar and other decoration provided by your window manager. You should only create one root widget for each program, and it must be created before any other widgets Chapter 3. Hello, Again root= Tko When you write larger programs, it is usually a good idea to wrap your code up in one or more Next, we create a label widget as a child to the root window: classes. The following example is adapted from the hello world " program in Matt Conway'sa TkinterLifePreserver(http://www.python.org/docstkinter) Id!'" wpack( Example 3-1, Our Second Tkinter Program A Label widget can display either text or an icon or other image. In this case, we use the text File: hello2. py option to specify which text to display. Next, we call the pack method on this widget, which tells it to size itself to fit the given text, and make itself visible. But before this happens, we from Tkinter Import have to enter the fkinter event loop class App root. mainlcopo def_ init(self, master) The program will stay in the event loop until we close the window. The event loop doesn t only handle events from the user(such as mouse clicks and key presses)or the windowing system frame Frame(master) (such as redraw events and window configuration messages), it also handle operations queued frame packo by Tkinter itself. Among these operations are geometry management (queued by the pack self. button Button(frame, text="QUIT, fg=red", command=frame. quit) method)and display updates. ' This also means that the application window will not appear elf. button pack(side=LEFT before you enter the main loop selt hi_there Button(frame, text-Hello", command-selt say hi) self. hi_there. pack(side=LEFT) print"hi there, everyone! root tk app App(root rcot. maInloopo Running the Example When you run this example, the following window appears Figure 3-1. Running the sample program(using Tk 8.0 on a windows 5 box) If you click the right button, the text"hi there, everyone! "is printed to the console. If you click the left button, the program stops Copyright(c)1999 by Fredrik Lundh Review Copy. Do not redistribute! 1999-12-01 22: 15 Chapter 3. Hello, Aga Chapter 3. Hello, Again Details The last call is to the mainloop method on the root widget. It enters the Tk event loop, in which the application will stay until the quit method is called gust click the QUIT button), or the This sample application is written as a class. The constructor [the init method)is called window is closed with a parent widget(the master ), to which it adds a number of child widgets The constructor starts by creating a Frame widget. A frame is a simple container and is in this case only uscd to More on widget references lold the other two widgets In the second example the frame widget is stored in a local variable named frame while the lass App button widgets are stored in two instance attributes. Isn' t there a serious problem hidden in def init (self, master) here: whal happens when the_init__ funclion returns and the frame variable goes out of frame- Frame(master) frame packo Just relax; there 's actually no need to keep a reference to the widget instance. Tkinter The frame instance is stored in a local variable called frame. After creating the widget, we automatically maintains a widget tree (via the master and children attributes of each widget instance), so a widget wont disappear when the application s last reference goes away it must immediately call the pack mcthod to make the frame visible be explicitly destroyed before this happens(using the destroy method). But if you wish to do We then create two Button widgets as children to the frame something with the widget after it has been created, you better keep a reference to the widget self. button Button(frame, text="QUiT", fg="red command= frame. quit self button. pack(side=LEFT) Note that if you don't need to keep a reference to a widget, it might be tempting to create and pack it on a single lin self. hi_there Button(frame, text-"Hello, command-selt say hi) self hl there pack(slde=LEFT) Button(frame, text-"Hello", com mand-self hello), pack(side-LEFT) This time, we pass a number of options to the constructor, as keyword arguments. ' The first Dont store the result from this operation; you l only get disappointed when you try to use that button is labelled"QUIT", and is madc red (fg is short for foreground). The second is labelled value(the pack method returns Ncne). To be on the safe side, it might be better to always Hello. Both buttons also take a command option. This option specifies a function, or(as in separate construction from packing this case)a bound method which will be called when the button is clicked W= Button(frame, text="Hel lo", command=self. hello) The button instances are stored in instance attributes. They are both packed, but this time with wpack(side=LEFT) the slde=LEFT argument. This means that they will be placed as far left as possible in the frame; the first button is placed at the frame's left edge, and the second is placed just to the right of the first one(at the left edge of the remaining space in the frame, that is). By default, More on widget names widgets are packed relative to their parent (which is master for the frame widget, and the Another source of confusion, especially for those who have some experience of programming frame itself for the buttons). If the side is not given, it defaults to TOP. Tk Tcl, is Tkinter's notion of the widget name. In Tel, you must explicitly name each The "hello button callback is given next. It simply prints a message to the console everytime widget. For example, the following fcl command creates a Button named"ok, as a child to a the button is pressed widget named"dialog"(which in turn is a child of the root window, "." def say_ hi(self) button. dialog. ok print hi there, everyor The corresponding Tkinter call would look like Finally, we provide some script level code that creates a Tk root widget, and one instance of the App class using the root widget as its parent ck= Button(dialog) roct tko However, in the Tkinter case, ok and dialog are references to widget instances, not the actual names of the widgets. Since: Tk ilself needs the names, Tkinler aulormalically assigns a unique app= App(root) name to each new widget In the above case, the dialog name is probably something like “128718,” and the button could be named“128718.1432920”. f you wish to get the full oct main loop name of a Tkinter widget, simply use the str function on the widget instance 1428748.1432920 Copyright(c)1999 by Fredrik Lundh

...展开详情
试读 90P tkinter高清文档
立即下载
限时抽奖 低至0.43元/次
身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
王南_2014 不错不错,好东西!
2019-03-25
回复
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
  • GitHub

  • 签到新秀

关注 私信
上传资源赚钱or赚积分
最新推荐
tkinter高清文档 29积分/C币 立即下载
1/90
tkinter高清文档第1页
tkinter高清文档第2页
tkinter高清文档第3页
tkinter高清文档第4页
tkinter高清文档第5页
tkinter高清文档第6页
tkinter高清文档第7页
tkinter高清文档第8页
tkinter高清文档第9页
tkinter高清文档第10页
tkinter高清文档第11页
tkinter高清文档第12页
tkinter高清文档第13页
tkinter高清文档第14页
tkinter高清文档第15页
tkinter高清文档第16页
tkinter高清文档第17页
tkinter高清文档第18页

试读结束, 可继续读2页

29积分/C币 立即下载