Tkinter 中Checkbutton的grid怎么用?

ironcat 2005-11-08 05:57:32
提示说参数不对。grid(row = row,col = col, sticky = W) 不知道哪里错了?
...全文
113 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ironcat 2005-11-12
  • 打赏
  • 举报
回复
还有个pwm的问题,ide提示没有定义,我觉得可能是我没有这个模块。
我应该到哪里下载这个模块呢?sourceforge上的链接有问题。
jimmy_kuu 2005-11-10
  • 打赏
  • 举报
回复
#参数写错了,不是col,是column
grid(row = row, column = col, sticky = W)
Abstract Describes the Tkinter widget set for constructing graphical user interfaces (GUIs) in the Python programming language. This publication is available in Web form1 and also as a PDF document2. Please forward any comments to tcc-doc@nmt.edu. Table of Contents 1. What is Tkinter?.......................................................................................................................3 2. A minimal application..............................................................................................................3 3. Definitions..............................................................................................................................4 4. Layout management.................................................................................................................5 4.1. The .grid() method....................................................................................................5 4.2. Other grid management methods...................................................................................6 4.3. Configuring column and row sizes.................................................................................7 4.4. Making the root window resizeable................................................................................8 5. Standard attributes...................................................................................................................8 5.1. Dimensions...................................................................................................................9 5.2. The coordinate system...................................................................................................9 5.3. Colors...........................................................................................................................9 5.4. Type fonts...................................................................................................................10 5.5. Anchors......................................................................................................................11 5.6. Relief styles.................................................................................................................12 5.7. Bitmaps.......................................................................................................................12 5.8. Cursors.......................................................................................................................12 5.9. Images........................................................................................................................14 5.10. Geometry strings........................................................................................................14 5.11. Window names...........................................................................................................15 5.12. Cap and join styles.....................................................................................................15 5.13. Dash patterns.............................................................................................................16 5.14. Matching stipple patterns............................................................................................16 6. The Button widget................................................................................................................17 7. The Canvas widget................................................................................................................19 7.1. Canvas coordinates......................................................................................................20 7.2. The Canvas display list................................................................................................20 7.3. Canvas object IDs........................................................................................................21 7.4. Canvas tags................................................................................................................21 1http://www.nmt.edu/tcc/help/pubs/tkinter/ 2http://www.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf 1 Tkinter reference New Mexico Tech Computer Center 7.5. CanvastagOrId arguments......................................................................................21 7.6. Methods on Canvas widgets........................................................................................21 7.7. Canvas arc objects.......................................................................................................26 7.8. Canvas bitmap objects.................................................................................................28 7.9. Canvas image objects..................................................................................................29 7.10. Canvas line objects.....................................................................................................29 7.11. Canvas oval objects....................................................................................................31 7.12. Canvas polygon objects..............................................................................................32 7.13. Canvas rectangle objects.............................................................................................34 7.14. Canvas text objects.....................................................................................................35 7.15. Canvas window objects..............................................................................................36 8. The Checkbutton widget......................................................................................................37 9. The Entry widget..................................................................................................................40 9.1. Scrolling an Entry widget............................................................................................43 10. The Frame widget................................................................................................................43 11. The Label widget................................................................................................................44 12. The LabelFrame widget......................................................................................................46 13. The Listbox widget............................................................................................................48 13.1. Scrolling a Listbox widget........................................................................................52 14. The Menu widget..................................................................................................................52 14.1. Menu item creation (coption) options.........................................................................55 14.2. Top-level menus.........................................................................................................56 15. The Menubutton widget......................................................................................................57 16. The Message widget............................................................................................................59 17. The OptionMenu widget.......................................................................................................60 18. The PanedWindow widget....................................................................................................61 18.1. PanedWindow child configuration options...................................................................63 19. The Radiobutton widget....................................................................................................64 20. The Scale widget................................................................................................................67 21. The Scrollbar widget........................................................................................................70 21.1. The Scrollbarcommand callback............................................................................72 21.2. Connecting a Scrollbar to another widget................................................................73 22. The Spinbox widget............................................................................................................73 23. The Text widget..................................................................................................................78 23.1. Text widget indices...................................................................................................80 23.2. Text widget marks....................................................................................................81 23.3. Text widget images...................................................................................................82 23.4. Text widget windows...............................................................................................82 23.5. Text widget tags.......................................................................................................82 23.6. Setting tabs in a Text widget......................................................................................83 23.7. The Text widget undo/redo stack..............................................................................83 23.8. Methods on Text widgets..........................................................................................84 24. Toplevel: Top-level window methods..................................................................................91 25. Universal widget methods.....................................................................................................93 26. Standardizing appearance...................................................................................................101 26.1. How to name a widget class......................................................................................102 26.2. How to name a widget instance.................................................................................102 26.3. Resource specification lines.......................................................................................102 26.4. Rules for resource matching......................................................................................103 27. Connecting your application logic to the widgets...................................................................104 28. Control variables: the values behind the widgets...................................................................104 29. Focus: routing keyboard input.............................................................................................106 New Mexico Tech Computer Center Tkinter reference 2 30. Events................................................................................................................................107 30.1. Levels of binding......................................................................................................108 30.2. Event sequences.......................................................................................................109 30.3. Event types..............................................................................................................109 30.4. Event modifiers........................................................................................................110 30.5. Key names...............................................................................................................111 30.6. Writing your handler: The Event class......................................................................113 30.7. The extra arguments trick..........................................................................................115 30.8. Virtual events...........................................................................................................116 31. Pop-up dialogs....................................................................................................................116 31.1. The tkMessageBox dialogs module..........................................................................116 31.2. The tkFileDialog module.....................................................................................118 31.3. The tkColorChooser module.................................................................................119
Table of Contents 1. What is Tkinter?.......................................................................................................................3 2. A minimal application..............................................................................................................3 3. Definitions..............................................................................................................................4 4. Layout management.................................................................................................................5 4.1. The .grid() method....................................................................................................5 4.2. Other grid management methods...................................................................................6 4.3. Configuring column and row sizes.................................................................................7 4.4. Making the root window resizeable................................................................................8 5. Standard attributes...................................................................................................................8 5.1. Dimensions...................................................................................................................9 5.2. The coordinate system...................................................................................................9 5.3. Colors...........................................................................................................................9 5.4. Type fonts...................................................................................................................10 5.5. Anchors......................................................................................................................11 5.6. Relief styles.................................................................................................................12 5.7. Bitmaps.......................................................................................................................12 5.8. Cursors.......................................................................................................................12 5.9. Images........................................................................................................................14 5.10. Geometry strings........................................................................................................14 5.11. Window names...........................................................................................................15 5.12. Cap and join styles.....................................................................................................15 5.13. Dash patterns.............................................................................................................16 5.14. Matching stipple patterns............................................................................................16 6. The Button widget................................................................................................................17 7. The Canvas widget................................................................................................................19 7.1. Canvas coordinates......................................................................................................20 7.2. The Canvas display list................................................................................................20 7.3. Canvas object IDs........................................................................................................21 7.4. Canvas tags................................................................................................................21 1http://www.nmt.edu/tcc/help/pubs/tkinter/ 2http://www.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf 1 Tkinter reference New Mexico Tech Computer Center 7.5. CanvastagOrId arguments......................................................................................21 7.6. Methods on Canvas widgets........................................................................................21 7.7. Canvas arc objects.......................................................................................................26 7.8. Canvas bitmap objects.................................................................................................28 7.9. Canvas image objects..................................................................................................29 7.10. Canvas line objects.....................................................................................................29 7.11. Canvas oval objects....................................................................................................31 7.12. Canvas polygon objects..............................................................................................32 7.13. Canvas rectangle objects.............................................................................................34 7.14. Canvas text objects.....................................................................................................35 7.15. Canvas window objects..............................................................................................36 8. The Checkbutton widget......................................................................................................37 9. The Entry widget..................................................................................................................40 9.1. Scrolling an Entry widget............................................................................................43 10. The Frame widget................................................................................................................43 11. The Label widget................................................................................................................44 12. The LabelFrame widget......................................................................................................46 13. The Listbox widget............................................................................................................48 13.1. Scrolling a Listbox widget........................................................................................52 14. The Menu widget..................................................................................................................52 14.1. Menu item creation (coption) options.........................................................................55 15. The Menubutton widget......................................................................................................56 16. The Message widget............................................................................................................58 17. The OptionMenu widget.......................................................................................................59 18. The PanedWindow widget....................................................................................................60 18.1. PanedWindow child configuration options...................................................................63 19. The Radiobutton widget....................................................................................................63 20. The Scale widget................................................................................................................66 21. The Scrollbar widget........................................................................................................69 21.1. The Scrollbarcommand callback............................................................................72 21.2. Connecting a Scrollbar to another widget................................................................73 22. The Spinbox widget............................................................................................................73 23. The Text widget..................................................................................................................77 23.1. Text widget indices...................................................................................................80 23.2. Text widget marks....................................................................................................81 23.3. Text widget images...................................................................................................82 23.4. Text widget windows...............................................................................................82 23.5. Text widget tags.......................................................................................................82 23.6. Setting tabs in a Text widget......................................................................................82 23.7. The Text widget undo/redo stack..............................................................................83 23.8. Methods on Text widgets..........................................................................................83 24. Toplevel: Top-level window methods..................................................................................90 25. Universal widget methods.....................................................................................................93 26. Standardizing appearance...................................................................................................100 26.1. How to name a widget class......................................................................................101 26.2. How to name a widget instance.................................................................................101 26.3. Resource specification lines.......................................................................................102 26.4. Rules for resource matching......................................................................................103 27. Connecting your application logic to the widgets...................................................................103 28. Control variables: the values behind the widgets...................................................................104 29. Focus: routing keyboard input.............................................................................................106 30. Events................................................................................................................................107 New Mexico Tech Computer Center Tkinter reference 2 30.1. Levels of binding......................................................................................................107 30.2. Event sequences.......................................................................................................108 30.3. Event types..............................................................................................................109 30.4. Event modifiers........................................................................................................110 30.5. Key names...............................................................................................................110 30.6. Writing your handler: The Event class......................................................................113 30.7. The extra arguments trick..........................................................................................114 30.8. Virtual events...........................................................................................................115 31. Pop-up dialogs....................................................................................................................116 31.1. The tkMessageBox dialogs module..........................................................................116 31.2. The tkFileDialog module.....................................................................................117 31.3. The tkColorChooser module.................................................................................118
CHAPTER 1 About Python ............................................................................................1 What Is Python? ................................................................................................................1 A Brief History of Python ................................................................................................2 Interpreters Versus Compilers .......................................................................................5 When to Use (or Not Use) an Interpreted Language .........................................8 Understanding Bytecodes ......................................................................................10 Why Use Python? ...........................................................................................................11 Object-Oriented ........................................................................................................11 Cross Platform ..........................................................................................................11 Broad User Base .......................................................................................................11 Well Supported in Third-Party Tools ...................................................................12 Good Selection of Tools Available ........................................................................12 Good Selection of Pre-built Libraries ..................................................................12 Where Is Python Used? .................................................................................................13 How Is Python Licensed? ..............................................................................................13 Where Do I Get Python? ...............................................................................................14 Installing Python ............................................................................................................14 Getting Information on Python ..................................................................................16 Python Communities .....................................................................................................17 Other Software ................................................................................................................18 And Now for Something Completely Different… ....................................................18 CHAPTER 2 Python Language Overview .................................................................19 Python Syntax .................................................................................................................20 Comments .................................................................................................................20 Indentation ...............................................................................................................20 Contents TABLE OF} vii Q Q Q Python Reserved Words ................................................................................................24 Decision Making and Iteration Keywords ..........................................................25 Debugging Keywords ..............................................................................................27 Package and Module Handling Keywords .........................................................27 Exception Handling Keywords ..............................................................................29 General Language Keywords .................................................................................31 Other Keywords ........................................................................................................32 Variable Usage ................................................................................................................34 The Continuation Variable ....................................................................................36 Watching Out for Spelling Mistakes! ..................................................................37 Predicates .........................................................................................................................38 Identifier Scope ...............................................................................................................39 Operators .........................................................................................................................42 Modulo Operator .....................................................................................................44 Exponential Operator .............................................................................................46 Logical Operators ....................................................................................................46 Comparative Operators ..........................................................................................49 Bitwise Operators ....................................................................................................51 Membership Operators and String Operators ..................................................53 Identity Operators ...................................................................................................53 In Conclusion ..................................................................................................................53 CHAPTER 3 Tools ..........................................................................................................55 IDLE ...................................................................................................................................55 File Menu ...................................................................................................................57 The Path Browser Dialog ........................................................................................62 Edit Menu ..................................................................................................................64 Shell Menu .................................................................................................................70 Debug Menu ..............................................................................................................71 The Edit Window ......................................................................................................79 Format Menu ............................................................................................................80 CONTENTS viii Q Q Q Command Line Compiler ..............................................................................................90 Creating Python Files ....................................................................................................93 Documentation ...............................................................................................................95 In Conclusion ..................................................................................................................96 CHAPTER 4 Data Types ...............................................................................................97 Numeric Types ................................................................................................................98 Integers ......................................................................................................................98 Demonstrating Long Integers ...............................................................................99 Octal and Hexadecimal ........................................................................................100 Floating Point Numbers .............................................................................................101 Strings ............................................................................................................................103 String Variables .....................................................................................................103 Concatenating Strings .........................................................................................106 Repeating Strings ..................................................................................................107 Substrings ...............................................................................................................108 Slicing ......................................................................................................................110 String Functions ....................................................................................................111 String Constants ....................................................................................................112 Conversion Functions ...........................................................................................114 Search Functions ...................................................................................................118 Formatting Functions ..........................................................................................120 Escape Sequences ..................................................................................................121 Sequences ......................................................................................................................122 Lists ..........................................................................................................................123 Shared References .................................................................................................128 Tuples .......................................................................................................................128 Dictionaries ............................................................................................................132 Advanced Type .............................................................................................................136 Classes and Objects ..............................................................................................136 Complex Type .........................................................................................................137 Generator Type ......................................................................................................138 CONTENTS ix Q Q Q None Type ...............................................................................................................139 Unicode Type ..........................................................................................................140 In Conclusion ................................................................................................................141 CHAPTER 5 Control Flow .........................................................................................143 Conditionals ..................................................................................................................144 The if Statement ..................................................................................................144 The elif Statement .............................................................................................147 The else Statement .............................................................................................149 Wrapping Up the Conditionals: A Cool Example ...........................................150 Loops ..............................................................................................................................153 The for Loop ..........................................................................................................153 The while Loop .....................................................................................................161 In Conclusion ................................................................................................................164 CHAPTER 6 Input and Output ................................................................................165 User Input ......................................................................................................................165 The input Function ..............................................................................................166 The raw_input Function ....................................................................................168 User Output ...................................................................................................................170 Formatting ..............................................................................................................172 File Input .......................................................................................................................175 File Output ....................................................................................................................177 Closing Files ..................................................................................................................179 Positioning in Files ......................................................................................................180 Directories and Files ...................................................................................................183 The stat Module: File Statistics ..............................................................................186 Command Line Arguments ........................................................................................190 Pickle ..............................................................................................................................192 In Conclusion ................................................................................................................195 CONTENTS x Q Q Q CHAPTER 7 Functions and Modules .....................................................................197 What Is a Function? ....................................................................................................197 Defining Functions in Python ...................................................................................197 What Are Arguments? ................................................................................................200 How Do You Pass an Argument to a Function? ....................................................201 Default Arguments ......................................................................................................203 Variable Default Arguments .....................................................................................205 Keyword Arguments ....................................................................................................206 Returning Values from Functions ............................................................................207 Returning Multiple Values from Functions ...........................................................209 Recursive Functions ....................................................................................................210 Passing Functions as Arguments .............................................................................212 Lambda Functions .......................................................................................................213 Variable Numbers of Arguments to a Function ....................................................215 Variable Scope in Functions ......................................................................................216 Using Modules ..............................................................................................................218 In Conclusion ................................................................................................................219 CHAPTER 8 Exception Handling ............................................................................221 Looking at Exceptions in Python ..............................................................................222 Traceback Example ......................................................................................................223 Understanding Tracebacks ........................................................................................224 Exceptions .....................................................................................................................225 Catching Exceptions with try..except .........................................................226 Multiple except Clauses .....................................................................................229 Blank except Clauses ..........................................................................................231 The else Clauses .........................................................................................................232 The finally Clause ....................................................................................................234 Raising Your Own Exceptions ...................................................................................235 Exception Arguments .................................................................................................237 User-Defined Exceptions ............................................................................................238 Working with the Exception Information ..............................................................239 CONTENTS xi Q Q Q exc_type ................................................................................................................239 exc_value ..............................................................................................................240 Using the with Clause for Files ................................................................................243 Re-throwing Exceptions .............................................................................................244 In Conclusion ................................................................................................................246 CHAPTER 9 Object-Oriented Programming .........................................................247 A Brief History of OOP ................................................................................................247 What Is an Object? ......................................................................................................248 Why Do We Use Objects? ...........................................................................................249 Reuse ........................................................................................................................249 Ease in Debugging .................................................................................................250 Maintainability ......................................................................................................250 The Attributes of Object-Oriented Development .................................................251 Abstraction .............................................................................................................251 Data Hiding ............................................................................................................252 Inheritance .............................................................................................................253 Polymorphism ........................................................................................................255 Terminology ..................................................................................................................256 Class .........................................................................................................................256 Object .......................................................................................................................256 Attribute ..................................................................................................................257 Method ....................................................................................................................258 Message Passing ....................................................................................................259 Event Handling ......................................................................................................260 Derivation ...............................................................................................................260 Coupling ..................................................................................................................261 Cohesion ..................................................................................................................261 Constants ................................................................................................................261 Other Concepts .............................................................................................................262 In Conclusion ................................................................................................................262 CONTENTS xii Q Q Q CHAPTER 10 Classes and Objects in Python ..........................................................265 Python Classes ..............................................................................................................265 Properties ......................................................................................................................267 Attribute Modifying Functions .................................................................................272 Private Attributes ........................................................................................................274 Doc Strings ....................................................................................................................275 Properties ......................................................................................................................277 The self Object ...........................................................................................................279 Methods .........................................................................................................................281 Special Methods ...........................................................................................................283 Initialization ...........................................................................................................283 Termination ............................................................................................................284 String Conversion ..................................................................................................285 Inheritance ....................................................................................................................287 Multiple Inheritance ...................................................................................................291 Using super ..................................................................................................................293 Polymorphism ..............................................................................................................295 Exception Classes .........................................................................................................297 Iterators .........................................................................................................................299 Operator Overloading .................................................................................................301 In Conclusion ................................................................................................................304 CHAPTER 11 The Python Library ..............................................................................305 Containers .....................................................................................................................305 Working with the deque Class ...........................................................................306 Math ................................................................................................................................312 Complex Math ..............................................................................................................313 Types ...............................................................................................................................315 Strings ............................................................................................................................318 Regular Expressions ....................................................................................................319 Patterns ...................................................................................................................320 Special Sequence Characters ..............................................................................323 CONTENTS xiii Q Q Q Compiling Regular Expressions .........................................................................323 Matching Strings ...................................................................................................324 Meta Characters ....................................................................................................326 Grouping .................................................................................................................327 System ............................................................................................................................328 Random Number Generation ....................................................................................330 Dates and Times ...........................................................................................................331 Creating a New Time ............................................................................................332 Time Operations ....................................................................................................332 Creating a New Date .............................................................................................333 Date Operations ....................................................................................................333 Time Zone Information ........................................................................................335 Operating System Interface .......................................................................................336 System Information ..............................................................................................336 Process Management ...........................................................................................337 In Conclusion ................................................................................................................341 CHAPTER 12 The GUI — TkInter ...............................................................................343 What Is TkInter? ...........................................................................................................343 Terms and Conditions .................................................................................................343 Event Handling ......................................................................................................344 Callbacks .................................................................................................................344 Widgets ....................................................................................................................345 Layout Managers ...................................................................................................345 Working with TkInter .................................................................................................346 Creating a Label ...........................................................................................................347 Frame Widgets and Centering ..................................................................................349 An Application with a Button ...................................................................................351 Working with Entry Fields and Grid Layouts ........................................................353 Creating a Class to Handle User Interfaces ...........................................................356 Working with List Boxes ............................................................................................358 Scrolling a List Box ................................................................................................361 CONTENTS xiv Q Q Q Menus .............................................................................................................................363 Context Menus .............................................................................................................366 Scale Widgets ................................................................................................................367 RadioButtons and CheckButton ...............................................................................370 Text Widgets .................................................................................................................373 In Conclusion ................................................................................................................375 CHAPTER 13 The Web Server—Apache ...................................................................377 Setting Up Apache .......................................................................................................377 Testing Apache .............................................................................................................378 Your First Python CGI Script: Hello Apache ...........................................................379 Examining the Hello Python Script ...................................................................380 The cgi-bin Directory ............................................................................................381 A Script for Displaying the Environment ...............................................................382 Receiving Data from an HTML File ..........................................................................384 Sending Data to an HTML File ..................................................................................387 How It All Works ...................................................................................................390 Dynamic HTML Displays Based on User Input ......................................................391 HTML Elements ............................................................................................................396 Cookies ...........................................................................................................................399 Uploading Files ............................................................................................................402 Redirection ....................................................................................................................403 Error Handling ..............................................................................................................405 In Conclusion ................................................................................................................406 CHAPTER 14 Working with Databases ...................................................................407 What Is a Database? ...................................................................................................407 Simple Database Terminology ...........................................................................408 What Is MySQL? ...........................................................................................................409 Downloading and Installing ......................................................................................409 Creating a New Database ..........................................................................................410 Creating a New User ....................................................................................................414 CONTENTS xv Q Q Q Opening an Existing Database .................................................................................415 Writing to a Database ................................................................................................417 Reading from a Database ..........................................................................................421 Updating a Database ..................................................................................................424 Deleting from a Database ..........................................................................................427 Searching a Database .................................................................................................430 In Conclusion ................................................................................................................436 CHAPTER 15 Putting It All Together .......................................................................437 Designing the Application .........................................................................................437 Program Flow .........................................................................................................437 User Interface Design ...........................................................................................438 Database Design ...................................................................................................439 Implementing the Database Tables ........................................................................440 Implementing the Forms ...........................................................................................442 Adding Reviews ............................................................................................................449 Adding the Review to the Database ........................................................................452 Listing the Reviews ......................................................................................................456 Deleting Books .............................................................................................................459 In Conclusion ................................................................................................................462 CHAPTER 16 Python and Graphics ..........................................................................463 The PIL Library ..............................................................................................................463 Downloading ..........................................................................................................464 Installing .................................................................................................................464 Verifying Your Installation ..................................................................................465 Creating a New Image ................................................................................................465 Function Parameters ............................................................................................466 Drawing on the Image ................................................................................................467 Drawing the Image ...............................................................................................468 Displaying the Image ...........................................................................................470 CONTENTS xvi Q Q Q

37,717

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧