python1231001无标题_python字符串入门演示幻灯片.pyw_python无标题栏窗口_python半透明窗口...

1 """

2 第五课 字符串入门3 """

4 from sprites import *

5

6 s = '第五课 字符串入门'

7 screen =Screen()8 screen.bgcolor('blue')9 screen.titlebar(False)10 root = screen._root #窗口对象

11 root.wm_attributes('-alpha',0.7) #设置窗口为全透明(0到1.0)

12 screen.setup(800,700)13

14 ft = ('楷体',38,'bold')15 t = Sprite(visible=False,pos=(-500,0))16 t.color('magenta')17 clock =Clock()18 for x in range(110):19 t.clear()20 t.write(s,align='center',font=ft)21 t.wait()22 t.fd(5)23 clock.tick(60)24

25 m1 = Mouse() #鼠标左键

26 while notm1.down():screen.update()27

28 for x in range(50):29 t.clear()30 t.write(s,align='center',font=ft)31 t.wait()32 t.fd(10)33 clock.tick(60)34

35 #以下是显示学习的内容段

36 studycontent = """

37 主要学习内容38

39 1、字符串的概念40

41 2、转义字符42

43 3、len命令44

45 4、str的加法和乘法46

47 5、字符串的索引48

49 6、索引错误50

51 7、字符串的不可变性52 """

53 t.color('white')54 t.clear()55 t.sety(-300) #这里修改菜单的显示y坐标

56 ft = ('楷体',24,'bold')57 s =studycontent58 while notm1.down():screen.update()59 #下面的代码显示主菜单

60 for x in range(110):61 t.clear()62 t.write(s,align='center',font=ft)63 t.wait()64 t.bk(5)65 clock.tick(60)66

67 screen.listen()68

69 defslow_write(t,string):70 """

71 t:角色,string:要显示的字72 本函数慢慢的显示字。73 """

74 string = string.split('\n') #换成列表

75 oldxy = t.position() #记录老的坐标

76 t.goto(-340,310) #到新的坐标

77 for line in string: #每一行字

78 for char in line: #每一个字符

79 t.write(char,align='center',font=ft)80 t.wait(0.2)81 cd = len(bytes(char,'gb2312'))82 if cd == 1:83 t.addx(20)84 else:85 t.addx(30)86 t.setx(-336)87 t.addy(-50)88 t.goto(oldxy)89

90 s1 = """

91 1、字符串的概念92 在Python中,字符串是用引号封闭的一些字符。93 用成对的双引号,单引号,或三引号封闭一些字94 符时都可以定义字符串。当然,我们可以把它95 赋值给一个变量。96 如 s='red',或者 c="yellow"都是定义字符串。97 用三引号封闭的话,在定义时可以直接敲回车。98 当输入type('a')时,会显示。99 str是英文string的前三个字母,它就是字符串的意思100 (单击返回主菜单)101 """

102 defpress1():103 t.clear()104 slow_write(t,s1)105 while notm1.down():screen.update()106 t.clear()107 t.write(s,align='center',font=ft)108 screen.onkeypress(press1,'1')109

110

111 s2 = """

112 2、转义字符113 在计算机里,有些字符是看不见的,114 如换行符写做\'\\n\'。115 当我们按键盘上的Tab键的时候,116 在文本框里会表现为跳一格。117 这就是在输入制表符,它写做\'\\t\'。118 当我们敲回车键时,就是输入回车符号,它写做\'\\r\'。119 那么,当我们要输入反斜杠本身时,要怎么输入呢?120 我们可以输入\'\\\\\'。来表示一个反斜杠。121 当我们用三引号定义字符串,并且在输入字符的时候122 敲了回车时,Python会自动帮我们加上换行符123 而不是回车符。(单击返回主菜单)124 """

125 defpress2():126 t.clear()127 slow_write(t,s2)128 while notm1.down():screen.update()129 t.clear()130 t.write(s,align='center',font=ft)131 screen.onkeypress(press2,'2')132

133

134 s3 = """

135 3、len命令136 len是求字符串中字符个数的命令。137 语法:len(字符串)。138 如len('风火轮编程')的结果是5。139 len(\'\\n\')的结果是1,这是由于\'\\n\'表示是一个换行符。140 len('') 的结果是0,这是由于''是空字符串。141 (单击返回主菜单)142 """

143 defpress3():144 t.clear()145 slow_write(t,s3)146 while notm1.down():screen.update()147 t.clear()148 t.write(s,align='center',font=ft)149 screen.onkeypress(press3,'3')150

151

152 s4 = """

153 4、str的加法和乘法154 连接字符串用加号即可。如'ab' + 'cd'155 字符串可以乘以一个整数,它会把字符串156 重复一定的次数。如len('风火轮编程'*3)157 的结果是15。(单击返回主菜单)158 """

159 defpress4():160 t.clear()161 slow_write(t,s4)162 while notm1.down():screen.update()163 t.clear()164 t.write(s,align='center',font=ft)165 screen.onkeypress(press4,'4')166

167

168 s5 = """

169 5、字符串的索引170 字符串中的每个字符有编号,从左到右数,171 编号从0开始的,这个编号叫做索引号。172 我们可以通过索引号访问字符串中的字符。173 方法:字符串名称[index],其中index表示索引号。174 假设有字符串s='abcdefg',那么s[0]就是'a',175 s[3]就是'd'。176 在字符串中,索引号也可以从右到左数。177 这个时候索引号是从-1开始。也就是说s[-1]178 表示倒数第一个字符,s[-2]表示倒数第二个字符,179 依此类推。(单击返回主菜单)180 """

181 defpress5():182 t.clear()183 slow_write(t,s5)184 while notm1.down():screen.update()185 t.clear()186 t.write(s,align='center',font=ft)187 screen.onkeypress(press5,'5')188

189 s6 = """

190 6、索引错误191 字符串中的字符是有一定数量的,也就是说192 索引号肯定有一定范围。假设有 s='abcdefg',193 那么它的索引号是从0到6。194 如果输入s[7]会怎么样呢,这个时候就会提示错误。195 这个错误叫indexError,即索引错误。196 我们实践一下索引错误。(单击返回主菜单)197 """

198 defpress6():199 t.clear()200 slow_write(t,s6)201 while notm1.down():screen.update()202 t.clear()203 t.write(s,align='center',font=ft)204 screen.onkeypress(press6,'6')205

206 s7 = """

207 7、字符串的不可变性208 字符串有一个特性就是它是不可变的。209 主要表现为,我们可以通过索引号访问它的某个210 字符,但不能修改它。假设有s='abcdefg',211 那么让s[0]='风'是不可以的,这是会出错的。212 (单击返回主菜单)213 """

214 defpress7():215 t.clear()216 slow_write(t,s7)217 while notm1.down():screen.update()218 t.clear()219 t.write(s,align='center',font=ft)220 screen.onkeypress(press7,'7')221

222

223

224 byebye = """

225 下次再见!226 """

227 defpressq():228 t.clear()229 t.color('cyan')230 t.home()231 t.write(byebye,align='center',font=('宋体',38,'bold'))232 while notm1.down():screen.update()233 screen.bye()234 screen.onkeypress(pressq,'q')235

236 #下面的代码让窗口可以拖动.

237 oldx =0238 oldy =0239 defstartmove(event):240 globaloldx,oldy241 oldx =event.x242 oldy =event.y243 defstopmove(event):244 globaloldx,oldy245 oldx =0246 oldy =0247 defmovewindow(event):248 globaloldx,oldy249 dx = event.x -oldx250 dy = event.y -oldy251 root.move(dx,dy)252 screen.cv.bind("", startmove)253 screen.cv.bind("", stopmove)254 screen.cv.bind("",movewindow)255 screen.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值