- Tkinter GUI Programming by Example
- David Love
- 300字
- 2021-08-27 18:49:11
Interactivity
When creating a program which runs on the command line, there are essentially only two ways to get input from the user.
The first is by parsing command-line arguments. These are the extra information written on the same line when running an executable from the command line. For example: python3 -i blackjack.py. Here, we have passed in a flag of -i telling the interpreter to end in interactive mode, and the filename blackjack.py.
The second is the one which we have used throughout our blackjack game – input. The input function allows the user to type anything in to the command line and returns this as a string. As you may have noticed from our constant need to use the lower function and a while loop to validate the user's choices, this is far from ideal.
Compare this to the various ways with which we collected information from the user in Chapter 1, Meet Tkinter. We replicated the input function's capabilities with an Entry widget. Whilst we could use multiple Entry widgets and validation loops in a graphical interface, this would not solve the problem.
In order to collect a choice of two options from the user, such as in the case of choosing between hit and stick, we could simply use two buttons. This means the user cannot pick an option which was not given.
When choosing to play again, it would make more sense to use one of the message box windows to get the user's choice. The askyesno box seems like the perfect choice for this job. This again removes the need to validate whether the user's answer is one we expected.
Even if the command-line version of the game had a way of conveniently gathering user input, there's also the question of familiarity.
- Getting Started with React
- The DevOps 2.4 Toolkit
- ADI DSP應(yīng)用技術(shù)集錦
- Java高并發(fā)核心編程(卷1):NIO、Netty、Redis、ZooKeeper
- 細(xì)說(shuō)Python編程:從入門到科學(xué)計(jì)算
- Vue.js光速入門及企業(yè)項(xiàng)目開發(fā)實(shí)戰(zhàn)
- Node.js區(qū)塊鏈開發(fā)
- Learning Android Application Testing
- Learning Apache Thrift
- 鋁合金陽(yáng)極氧化與表面處理技術(shù)(第三版)
- MATLAB計(jì)算機(jī)視覺(jué)實(shí)戰(zhàn)
- 深入實(shí)踐C++模板編程
- FORTRAN程序設(shè)計(jì)權(quán)威指南
- Oracle API Management 12c Implementation
- Python大數(shù)據(jù)與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)