'Zhuan' Python Intermediate Tutorial 3 — Prompt Box Buttons
Python Intermediate Tutorial Three - The text in the prompt window has been relatively busy recently, so the tutorial has been slow to come out. Please be patient and wait for a few more sections of my tutorial. Without further ado, let's start the tutorial now. I wonder if you still remember the prompt box in the first section? If you don't know it, go and review it quickly because you will need it in this section.Let's look at some codes first: dialogSetPositiveButtonText ('') This is used to display the OK button, which is the one on the left. dialogSetNeutralButtonText ('') is used to display the neutral button, which is the one in the middle. dialogSetNegativeButtonText ('') is used to display the negative button, which is the one on the right. Okay, now let's look at the code together: import android #coding=utf-8 droid =android. Android() droid. dialogCreateAlert('Prompt', 'Three buttons') droid. dialogSetPositiveButtonText('OK') droid. dialogSetNeutralButtonText('Return') droid. dialogSetNegativeButtonText('Cancel') droid. dialogShow() response=droid. dialogGetResponse(). result if response. has_key('which'): ~~~~result=response['which'] ~~~~if result=='positive': ~~~~~~~~droid. makeToast('OK') ~~~~elif result=='neutral': ~~~~~~~~droid. makeToast('Return') ~~~~elif result=='negative': ~~~~~~~~droid. makeToast('Cancel') elif response. has_key('canceled'): droid. makeToast('Exit') The result is as shown in Figure 1: Now let's look at this response=droid. dialogGetResponse(). result, it means to use dialogGetresponse to get the event value and assign it to response response. has_key ('which') This is used to check whether the user clicked the button, and the last canceled button is the return button on the physical phone. result = response ['which'] This is to pass the event of the button click to the result, and determine which button was clicked. if~result=='positive': This is when the result is equal to positive, the following statement is executed. Same thing below. droid. makeToast ('') is a short prompt, and the content inside the single quotes is the content to be prompted. elif is the abbreviation of else and if, which means to choose otherwise. Okay, the code has been explained. I don't know if you understand it. If you still don't understand, please post a question. There will be no homework in this section! We'll talk about the rest later. The second resource is the teaching code for this section, changed to py "End" Replying to posts is a virtue!
×
❮
❯
Replies (1)
Sofa...
— All replies loaded —