首页 > > 详细

代做Tic-Tac-Toe作业、代写C++,Java编程设计作业、Python语言作业代做、代写Game Board作业代做留学生Processing|帮做R

Project Part 4
Chapters 10 & 11
10.2 What is Tkinter
10.4 Creating a Window for Tic-Tac-Toe
10.5 Creating the Game Board
10.7 Using Label Widget
10.8 Using Button Widget
10.9 Creating Other Labels
11.8 Using Images
Buttons
Buttons
Nested for-loop
1. The part highlighted below in the image can be set up by using a nested for-loop. The outer forloop
works 10 times vertically and the inner for-loop works 3 times horizontally.
2. One of the statements in the outer for-loop include a Label widget to show the numbers from 1 to
10 which should come from the counter variable of the outer for-loop. As the content from the
counter variable is an integer, you have to change it to a string (using the str() function) before
using it in the attribute “text=string” in the Label widget.
3. For the inner for-loop, it should show two Label widgets each time it is executed. One is for the
small rectangle to be used for the peg and the other is an empty label which will be used to show
image later.
4. To position the Label widgets correctly using the grid layout, the row and column index numbers
can be integers, variables or integers plus variables. Assuming that the value of the variable used in
the examples below will start its value from zero and will increase its value one by one (i.e. the
increment is 1). The variable may come from the counter variable of the for-loop.
a. For example, to show the numbers from 1 to 10 in the second column, you may use an integer
as the column index, i.e. “column=1” and a variable as the row index, i.e. “row=variable”.
b. If you want to start the first label in the second row, the second label in the third row and so
on, you may use an integer plus a variable for the row index, i.e. “row=1+variable”. The integer
1 indicates which row to start, i.e. the second row.
c. If you want to start the first label in the second row, the second label in the fourth row and so
on, then you have to multiply the variable with 2, i.e. “row=1+variable*2”. The integer 2
indicates how many rows to jump or skip.
5. In the Label widget, you may use the attribute “relief=RAISED” inside the parentheses to give an
outline border to the label. You may use other relief as shown in page 152.
6. The width and height of the Label widget is determined by the attributes “width=x” and “height=x”
where x is an integer. You have to set the width and height of the labels to be similar size of the
images that you are going to replace them later in the game.
7. Lastly, there are only 5 statements in the nested for-loop just mentioned above to generate the
highlighted area as shown in the below image.
The five statements of the nested for-loop will be:
for …
Label(…).grid(…)
for …
Label(…).grid(…)
Label(…).grid(…)
Try to use a nested
for-loop to set up this
part.
Examples of using for-loop to generate Label widgets
1. Five Label widgets with border in a vertical position in the first column
for x in range(5):
Label(main_window, text="", width=10, height=2, relief=RAISED, bg="light grey").grid(row=x, column=0)
2. Five Label widgets with text in a vertical position in the first column
for x in range(5):
Label(main_window, text="GEB204", width=10, height=2, relief=RAISED, bg="light grey").grid(row=x, column=0)
3. Five Label widgets with numbers (starting from 1) in a vertical position in the first column
for x in range(5):
Label(main_window, text=str(x+1), width=10, height=2, relief=RAISED, bg="light grey").grid(row=x, column=0)
4. Five Label widgets with border in a vertical position in the second column(Assuming a red Label
widget is placed in the first row)
for x in range(5):
Label(main_window, text="", width=10, height=2, relief=RAISED, bg="light grey").grid(row=x+1, column=1)
5. Five Label widgets with border in a horizontal position in the second row
for x in range(5):
Label(main_window, text="", width=10, height=2, relief=RAISED, bg="light grey").grid(row=1, column=x+1)
6. Ten Label widgets (half with border) in a horizontal position in the second row
for x in range(5):
Label(main_window, text="", width=10, height=2, relief=RAISED, bg="light grey").grid(row=1, column=x*2+1)
Label(main_window, text="", width=1, bg="light grey").grid(row=1, column=x*2+2)
7. Fifteen Label widgets with border in both vertical and horizontal position (3 rows x 5 columns),
from the second row
for x in range(3):
for y in range(5):
Label(main_window, text="", width=10, height=2, relief=RAISED, bg="light grey").grid(row=1+x, column=1+y)

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点文章
程序代写更多图片

联系我们 - QQ: 99515681 微信:codinghelp
© 2014 www.7daixie.com
程序代写网!