python兒童編程PPT演示課件(PPT 72頁)_第1頁
python兒童編程PPT演示課件(PPT 72頁)_第2頁
python兒童編程PPT演示課件(PPT 72頁)_第3頁
python兒童編程PPT演示課件(PPT 72頁)_第4頁
python兒童編程PPT演示課件(PPT 72頁)_第5頁
已閱讀5頁,還剩67頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、初級(jí)編程2018/3/17 并非所有的蛇都會(huì)爬行1第1頁,共72頁。第一章 開始P2你將了解 什么是python 在計(jì)算機(jī)上安裝并使用python第2頁,共72頁。1.Python介紹一種計(jì)算機(jī)語言 高級(jí)語言(Java,Vb,Ruby,Python,C等多達(dá)上百種)P3和人類一樣,計(jì)算機(jī)使用多種語言進(jìn)行交流。一個(gè)編程語言只是一種與計(jì)算機(jī)對(duì)話的特殊方式。人類和計(jì)算機(jī)都能理解的指令。第3頁,共72頁。2.安裝Python-1獲取安裝程序(下載) /downloads/windows/ 注意根據(jù)操作系統(tǒng)選擇下載64或32位版本(可執(zhí)行文件)在windows下執(zhí)行安裝程序P4第4頁,共72頁。2.安裝

2、Python-2啟動(dòng)python shell(IDLE)P5這就是Python ShellPython Shell就是在計(jì)算機(jī)上解釋執(zhí)行python語言的控制臺(tái)。相當(dāng)于你的大腦負(fù)責(zé)解釋你和別人所說的話,并按照要求進(jìn)行動(dòng)作。第5頁,共72頁。3.和計(jì)算機(jī)交流吧你告訴計(jì)算機(jī)的第一句話 print(Hello World) Hello World P6讓計(jì)算機(jī)做幾道數(shù)學(xué)題 3 * 52 156 3670 - 156 3514 Symbol Operation+ Addition(加)- Subtraction(減)* Multiplication(乘)/ Division(除)第6頁,共72頁。第二

3、章 編程第一步(變量)P7你將了解 什么是變量? 它能干什么? 如何使用它第7頁,共72頁。4.什么是變量變量(variable) 編程中的變量描述了存儲(chǔ)信息的地方。比如數(shù)字、文本、數(shù)字和文本等等。從另一方面看,變量就像一個(gè)標(biāo)簽。P8 fred = 100 #定義一個(gè)變量,并給變量賦值 print(fred) #告訴計(jì)算機(jī)把變量表示的內(nèi)容顯示出來100 fred = 200 #定義一個(gè)變量,并給變量賦值 john = fred #定義另一個(gè)變量,并把fred的值賦值給它 print(john)200 found_coins = 20 magic_coins = 10 stolen_coins

4、= 3 found_coins + magic_coins * 2 - stolen_coins * 331第8頁,共72頁。第三章 編程第二步(常用數(shù)據(jù))P9你將了解 STRINGS - 字符串 LISTS - 列表 TUPLES - 元組 MAPS - 地圖第9頁,共72頁。1.字符串StringString(字符串)在編程術(shù)語中,我們通常稱文本為字符串。你可以把一個(gè)字符串看作字母的集合,本資料里所有的字母、數(shù)字和符號(hào)都是一串字符。P10 fred = What is pink and fluffy? Pink fluff! print(fred)What is pink and fluf

5、fy? Pink fluff!創(chuàng)造一個(gè)字符串,把它放在變量里,讓計(jì)算機(jī)顯示出來說明字符串用” 或者 來定義字符串轉(zhuǎn)義符號(hào) , 試著頂一個(gè) IAM COMPUTER第10頁,共72頁。1.字符串String在字符串種嵌入值P11 myscore = 1000 message = I scored %s points print(message % myscore)I scored 1000 points nums = What did the number %s say to the number %s? Nice belt! print(nums % (0, 8)What did the nu

6、mber 0 say to the number 8? Nice belt!字符串乘法 print(10 * a)Aaaaaaaaaa試試下面的輸出結(jié)果spaces = * 25print(%s 12 Butts Wynd % spaces)第11頁,共72頁。2.比字符串更強(qiáng)大的列表(list)LIST(列表) 很多變量的集合,用進(jìn)行定義P12 some_numbers = 1, 2, 5, 10, 20 some_strings = Which, Witch, Is, Which定義一個(gè)list你可以對(duì)list進(jìn)行如下操作 some_ some_strings.append(bear bu

7、rp) #追加項(xiàng)目 del some_strings2 #刪除第3項(xiàng) print(some_strings2:3) #顯示第3-4項(xiàng) print(some_strings) #顯示所有項(xiàng) print(some_numbers + some_strings) #可以做加法 print(some_numbers * 5) #可以做乘法除法,減法不行哦!考慮一下為什么第12頁,共72頁。2.另一種列表元祖(tuples)TUPLE(元祖)元組類似于使用圓括號(hào)的列表,用()進(jìn)行定義,區(qū)別是創(chuàng)建后不能更改P13 fibs = (0, 1, 1, 2, 3) print(fibs3)定義一個(gè)tuple你不

8、可以改變tuple的內(nèi)容否則計(jì)算機(jī)給給你報(bào)錯(cuò) fibs0 = 4Traceback (most recent call last):File , line 1, in fibs0 = 4TypeError: tuple object does not support item assignment第13頁,共72頁。2.幫你找到你想要的(字典)MAP(字典)字典中的每一項(xiàng)都有一個(gè)鍵和一個(gè)對(duì)應(yīng)的值。你可以根據(jù)鍵找到值。P14 favorite_sports = Ralph Williams : Football,Michael Tippett :Basketball,Edward Elgar :

9、 Baseball,Rebecca Clarke : Netball,Ethel Smyth : Badminton,Frank Bridge : Rugby定義一個(gè)map你可以對(duì)字典做如下操作 print(favorite_sportsRebecca Clarke) #找到RebeccaClarke喜歡的運(yùn)動(dòng)del favorite_sportsEthel Smyth #從字典中刪除EthelSmyth數(shù)據(jù)favorite_sportsEthel Smyth = Ice Hockey #修改Ethel Smyth喜歡的運(yùn)動(dòng)favorite_sportsCan Can=tennis #追加ca

10、ncan喜歡的項(xiàng)目第14頁,共72頁。第四章 海龜畫圖P15你可以畫出絢麗的圖案第15頁,共72頁。1.什么是海龜P16Turbles是一個(gè)畫板模塊,你可以利用它繪圖。正如你寫字并不需要你去制造鉛筆和紙張,你可以利用turtle去繪畫第16頁,共72頁。2.海龜繪圖P17import turtle #引進(jìn)海龜,你可以開始使用它turtle.pencolor(red) #設(shè)置畫筆顏色(紅色)turtle.pensize(1) #設(shè)置畫筆粗細(xì)turtle.forward(100) #讓海龜前進(jìn)50個(gè)像素turtle.left(90) #左轉(zhuǎn)90度turtle.forward(100) #讓海龜繼續(xù)

11、前進(jìn)50個(gè)像素turtle.left(90) #左轉(zhuǎn)90度turtle.forward(100) #讓海龜繼續(xù)前進(jìn)50個(gè)像素turtle.left(90) #左轉(zhuǎn)90度turtle.forward(100) #讓海龜繼續(xù)前進(jìn)50個(gè)像素turtle.up() #讓海龜抬起筆turtle.left(90) #左轉(zhuǎn)90度turtle.forward(50) #讓海龜繼續(xù)前進(jìn)25個(gè)像素turtle.down() #讓海龜放下筆turtle.pencolor(green) #設(shè)置畫筆顏色(綠色)turtle.pensize(3) #設(shè)置畫筆粗細(xì)turtle.circle(50) #畫一個(gè)半徑50的圓第1

12、7頁,共72頁。3.運(yùn)用技巧P18import turtle #引進(jìn)海龜,你可以開始使用它myColor=red,green,brownindex =0for x in range(250): turtle.pencolor(myColorindex) index +=1 if index = 3: index = 0 turtle.forward(x*2) turtle.left(92)右邊的圖怎么畫出來的?看看下面的代碼讓計(jì)算機(jī)干了什么第18頁,共72頁。第五章 邏輯判斷P19用IF ELSE判斷邏輯第19頁,共72頁。1. 邏輯判斷P20age = 10if age = 20: prin

13、t(oh!you are yong)Elif age 20 and age = 10 and age myval = None if myval = None:print(The variable myval doesnt have a value)什么都沒有保存的空值 age=10 if age = 10:print(The variable myval doesnt have a value)數(shù)值是字符串還是數(shù)字? age=10 if age = 10:print(The variable myval doesnt have a value) age = 10 converted_age

14、= int(age) age = 10 converted_age = str(age) age = 10.5 converted_age = int(age) if age = 10:print(The variable myval doesnt have a value)結(jié)果如何第23頁,共72頁。第六章 重復(fù)事件處理P24第24頁,共72頁。1. 循環(huán)P25作業(yè)要抄寫100遍? NO! print(“homework”)print(“homework”)print(“homework”)print(“homework”)print(“homework”)print(“homework”)

15、print(“homework”)print(“homework”)print(“homework”).print(“homework”)print(“homework”)print(“homework”)print(“homework”)so easy!for x in range(0, 99): print(homework)for x in range(0, 99): print(hello %s % x)試試這個(gè)第25頁,共72頁。2. 列表(list)的循環(huán)P26 print(list(range(10, 20)10, 11, 12, 13, 14, 15, 16, 17, 18,

16、19簡單的列表打印class_list = class1,class2,class3,class4,class5 for x in range(0, 4): print(hello %s % class_listx)循環(huán)方式的列表打印循環(huán)方式的遍歷列表 wizard_list = spider legs, toe of frog, snail tongue,bat wing, slug butter, bear burp for i in wizard_list:print(i)左邊的1和2實(shí)現(xiàn)方式有什么區(qū)別?hugehairypants = huge, hairy, pantsfor i i

17、n hugehairypants: print(i) for j in hugehairypants: print(j)推測(cè)一下下面的結(jié)果第26頁,共72頁。3. 一道循環(huán)的計(jì)算題P27問題 寶箱里有20枚金幣,每天會(huì)增加10枚,但是烏鴉每周會(huì)偷走3枚,請(qǐng)計(jì)算一年53周每周寶箱內(nèi)會(huì)剩余多少金幣 found_coins = 20 magic_coins = 70 stolen_coins = 3u coins = found_coinsv for week in range(1, 53):w coins = coins + magic_coins - stolen_coinsx print(We

18、ek %s = %s % (week, coins)第27頁,共72頁。4. 循環(huán)處理的幾種語法P28for step in range(0, 20): print(step)FOR循環(huán)x = 45y = 80 while x 50 and y 100: x = x + 1 y = y + 1 print(x, y)WHILE循環(huán)for x in range(0, 20): print(hello %s % x) if x 9: breakBreak可以提前退出循環(huán)第28頁,共72頁。第七章 模塊和函數(shù)P29函數(shù)是一些處理邏輯的集合模塊是函數(shù),變量的集合擁有更強(qiáng)大的功能海龜就是一個(gè)繪圖模塊第2

19、9頁,共72頁。1. 函數(shù)構(gòu)成P30def testfunc(myname): print(hello %s % myname)函數(shù)名,參數(shù),處理testfunc(Mary)print(savings(10, 10, 5)執(zhí)行函數(shù)def testfunc(fname, lname): print(Hello %s %s % (fname, lname)函數(shù)可以有多個(gè)參數(shù)函數(shù)可以有返回值def savings(pocket_money, paper_route, spending): return pocket_money + paper_route spending第30頁,共72頁。2. 一

20、個(gè)函數(shù)的例子P31每周生產(chǎn)X個(gè)罐子,計(jì)算出一年中每周位置總共生產(chǎn)的罐子。def spaceship_building(cans): total_cans = 0 for week in range(1, 53): total_cans = total_cans + cans print(Week %s = %s cans % (week, total_cans)函數(shù)調(diào)用spaceship_building(2) #A工廠每周只能生產(chǎn)2個(gè)spaceship_building(10) #B工廠每周只能生產(chǎn)10個(gè)考慮一下使用函數(shù)的好處第31頁,共72頁。P323. 模塊(moudle)如何導(dǎo)入模塊i

21、mport sys #導(dǎo)入系統(tǒng)模塊Import turtle #導(dǎo)入海龜繪圖模塊只有導(dǎo)入模塊后,才可以使用它第32頁,共72頁。P334. 使用sys模塊sys模塊內(nèi)部有一個(gè)特殊的對(duì)象稱為stdin(標(biāo)準(zhǔn)輸入),它提供了一個(gè)相當(dāng)有用的函數(shù)readline。ReadLine函數(shù)用于讀取一行文本類型在鍵盤上,直到按回車鍵。Standard input的略稱import sysdef ageEV(): print(How old are you?) age = int(sys.stdin.readline() if age 15 and age ozwald = Giraffes(100) gert

22、rude = Giraffes(150) print(ozwald.giraffe_spots)100 print(gertrude.giraffe_spots)150初期化函數(shù)的例子初期化函數(shù)的使用實(shí)例第41頁,共72頁。第九章 python自帶的常用函數(shù)P42第42頁,共72頁。P431. Python自帶函數(shù)-1獲得絕對(duì)值 abs() print(abs(10)10布爾變量 bool() print(bool(0)False print(bool(1)True print(bool(a)Dir函數(shù) print(bool(0)False print(bool(1)True print(bo

23、ol(a)#用它來計(jì)算絕對(duì)值#用它來取得邏輯真假,可進(jìn)行IF判斷 還記得條件語法嗎 if elif else#它的參數(shù)是任意類型,執(zhí)行結(jié)果可以告訴你,可以處理這種類型所有的函數(shù)。你需要從一堆結(jié)果中找出自己有用 的信息。看看下面的記過,對(duì)于整數(shù)你可以利用那些函數(shù)。 print(dir(1)_abs_, _add_, _and_, _bool_, _ceil_, _class_, _delattr_, _dir_, _divmod_, _doc_, _eq_, _float_, _floor_, _floordiv_, _format_, _ge_, _getattribute_, _getnew

24、args_, _gt_, _hash_, _index_, _init_, _init_subclass_, _int_, _invert_, _le_, _lshift_, _lt_, _mod_, _mul_, _ne_, _neg_, _new_, _or_, _pos_, _pow_, _radd_, _rand_, _rdivmod_, _reduce_, _reduce_ex_, _repr_, _rfloordiv_, _rlshift_, _rmod_, _rmul_, _ror_, _round_, _rpow_, _rrshift_, _rshift_, _rsub_, _

25、rtruediv_, _rxor_, _setattr_, _sizeof_, _str_, _sub_, _subclasshook_, _truediv_, _trunc_, _xor_, bit_length, conjugate, denominator, from_bytes, imag, numerator, real, to_bytes第43頁,共72頁。P442. Python自帶函數(shù)-2獲得幫助help help(abs)Help on built-in function abs in module builtins:abs(x, /) Return the absolute

26、 value of the argument.執(zhí)行命令函數(shù) eval your_calculation = input(Enter a calculation: )Enter a calculation: 12*52 eval(your_calculation)624#用它讓Python告訴你函數(shù)的使用方法,不過都是英文哦!執(zhí)行命令函數(shù) eval my_small_program = print(ham)print(sandwich) exec(my_small_program)hamsandwich區(qū)別 eval 可以有返回值 exec 無返回值第44頁,共72頁。P453. Python自

27、帶函數(shù)-3浮點(diǎn)值 float() print(abs(10)10整數(shù) int() float(123.456789)123.456789 your_age = input(Enter your age: )Enter your age: 20 age = float(your_age) if age 13:print(You are %s years too old % (age - 13)You are 7.0 years too old#帶很多位小數(shù)的值 int(123.456)123 int(123)123 int(123.456)Traceback (most recent call

28、last):File , line 1, in int(123.456)ValueError: invalid literal for int() with base 10: 123.456出錯(cuò)了!字符串123.456不可以第45頁,共72頁。P464. Python自帶函數(shù)-4取得長度 len len(this is a test string)21 creature_list = unicorn, cyclops, fairy, elf, dragon,troll print(len(creature_list)6取得最大數(shù),最小值 max min numbers = 5, 4, 10,

29、30, 22 print(max(numbers)30 strings = s,t,r,i,n,g,S,T,R,I,N,G print(max(strings)t范圍函數(shù) range for x in range(0, 5):print(x) count_by_twos = list(range(0, 30, 2) print(count_by_twos)0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28 count_down_by_twos = list(range(40, 10, -2) print(count_down_by_two

30、s)40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12第46頁,共72頁。P475. Python自帶函數(shù)-5計(jì)算和文件訪問 test_file = open(c:test.txt) text = test_file.read() print(text)文件內(nèi)容xxxxxxxxx my_list_of_numbers = list(range(0, 500, 50) print(my_list_of_numbers)0, 50, 100, 150, 200, 250, 300, 350, 400, 450 print(sum(m

31、y_list_of_numbers)2250 test_file = open(c:myfile.txt, w) test_file.write(What is green and loud? A froghorn!) test_file.close()讀取文件寫入文件第47頁,共72頁。第十章 python常用的模塊P48Python模塊是函數(shù)、類和變量的集合。為了使它們更容易使用。 Python使用模塊來分組函數(shù)和類。例如,海龜模塊,我們?cè)谇皫渍率褂盟?,用它?chuàng)建的畫布在屏幕上畫畫。第48頁,共72頁。P491. 復(fù)制模塊 copy -1導(dǎo)入復(fù)制模塊復(fù)制模塊的使用實(shí)例 class Anima

32、l:def _init_(self, species, number_of_legs, color):self.species = speciesself.number_of_legs = number_of_legsself.color = colorimport copy import copy #導(dǎo)入復(fù)制模塊 harry = Animal(hippogriff, 6, pink) #創(chuàng)建harry對(duì)象 harriet = copy.copy(harry) #把harry復(fù)制到harriet print(harry.species) #輸出harry的species屬性hippogriff

33、 print(harriet.species) #輸出hariet的species屬性hippogriff作用 把一個(gè)對(duì)象復(fù)制給另一個(gè)對(duì)象就像你在復(fù)印機(jī)上復(fù)印資料一樣寫入文件創(chuàng)建一個(gè)動(dòng)物類第49頁,共72頁。P502. 復(fù)制模塊 copy-2Copy 和 deepcopy harry = Animal(hippogriff, 6, pink) carrie = Animal(chimera, 4, green polka dots) billy = Animal(bogill, 0, paisley) my_animals = harry, carrie, billy more_animals

34、 = copy.copy(my_animals) print(more_animals0.species)hippogriff print(more_animals1.species)Chimera my_animals0.species = ghoul print(my_animals0.species)ghoul print(more_animals0.species)ghoul more_animals = copy.deepcopy(my_animals) my_animals0.species = wyrm print(my_animals0.species)Wyrm print(m

35、ore_animals0.species)ghoul第50頁,共72頁。P513. Python的關(guān)鍵字模塊關(guān)鍵字 keyword import keyword print(keyword.iskeyword(if)True print(keyword.iskeyword(ozwald)False print(keyword.kwlist)False, None, True, and, as, assert, break, class,continue, def, del, elif, else, except, finally,for, from, global, if, import, i

36、n, is, lambda,nonlocal, not, or, pass, raise, return, try, while,with, yield通過關(guān)鍵字模塊輸出python關(guān)鍵字,幫助我們認(rèn)識(shí)到python語言中那些單詞是有特殊意義的,我們定義變量和函數(shù)時(shí)需要避開重名。第51頁,共72頁。P524. 隨機(jī)函數(shù)模塊 randomrandom 返回制定范圍的隨機(jī)值 import random print(random.randint(1, 100)58 print(random.randint(100, 1000)861choice 從列表隨機(jī)取出一個(gè)項(xiàng)目 import random d

37、esserts = ice cream, pancakes, brownies, cookies,candy print(random.choice(desserts)browniesShuffle 把列表洗牌重新排序 import random desserts = ice cream, pancakes, brownies, cookies,candy random.shuffle(desserts) print(desserts)pancakes, ice cream, candy, brownies, cookies第52頁,共72頁。P535. 系統(tǒng)模塊對(duì)控制臺(tái)進(jìn)行操作 sysexi

38、t 關(guān)閉控制帶 import sys sys.exit()stdin.readline 從控制臺(tái)讀入輸入信息 import sys v = sys.stdin.readline()He who laughs last thinks slowest print(v)He who laughs last thinks sloweststdout.write 把內(nèi)容輸出到控制臺(tái) import sys sys.stdout.write(What does a fish say when it swims into a wall?Dam.)What does a fish say when it swi

39、ms into a wall? Dam.52 import sys print(sys.version)3.1.2 (r312:79149, Mar 21 2013, 00:41:52) MSC v.1500 32 bit (Intel)version 顯示系統(tǒng)版本第53頁,共72頁。P546. 時(shí)間模塊 time-1time 取得現(xiàn)在時(shí)間 import time print(time.time()1300139149.34 def lots_of_numbers(max):u t1 = time.time()v for x in range(0, max):print(x)w t2 = ti

40、me.time()x print(it took %s seconds % (t2-t1) lots_of_numbers(1000)January 1, 1970, at 00:00:00計(jì)算經(jīng)過的時(shí)間time.asctime 取得可讀的時(shí)間 import time print(time.asctime()Mon Mar 11 22:03:41 2013 import time t = (2020, 2, 23, 10, 30, 48, 6, 0, 0) print(time.asctime(t)Sun Feb 23 10:30:48 2020time.asctime 自己定義一個(gè)時(shí)間第54

41、頁,共72頁。P557. 時(shí)間模塊 time-2time.localtime 取得現(xiàn)在時(shí)間的列表 import time print(time.localtime()time.struct_time(tm_year=2020, tm_mon=2, tm_mday=23, tm_hour=22,tm_min=18, tm_sec=39, tm_wday=0, tm_yday=73, tm_isdst=0) t = time.localtime() year = t0 month = t1 print(year)2020 print(month)2time.sleep 讓計(jì)算機(jī)休息一會(huì)兒 for

42、x in range(1, 61):print(x)time.sleep(1)第55頁,共72頁。P568. 保存信息模塊 pickle保存map信息到文件 import picklev game_data = player-position : N23 E45,pockets : keys, pocket knife, polished stone,backpack : rope, hammer, apple,money : 158.50w save_file = open(save.dat, wb)x pickle.dump(game_data, save_file)y save_file

43、.close()從文件讀取保存的信息 load_file = open(save.dat, rb) loaded_game_data = pickle.load(load_file) load_file.close() print(loaded_game_data)money: 158.5, backpack: rope, hammer, apple,player-position: N23 E45, pockets: keys, pocket knife,polished stone第56頁,共72頁。第十章 高級(jí)海龜繪圖P57第57頁,共72頁。P581. 進(jìn)階海龜繪圖運(yùn)用學(xué)到的知識(shí)試試海

44、龜畫出下面的圖第58頁,共72頁。第十一章 圖形界面P59第59頁,共72頁。P601. 什么是圖形界面你現(xiàn)在使用的計(jì)算機(jī)就是圖形界面(例如)第60頁,共72頁。P612. Python的圖形界面Python的圖形包Import tkinter要開發(fā)圖形界面,首先要導(dǎo)入圖形包Python的圖形接口tkniter.Tk()創(chuàng)建基本的窗口Python的窗口控件tkniter.Button()按鍵tkniter.Canvas()用來在窗口畫圖的畫布等等。Python的窗口更新顯示xxxx.Pack()當(dāng)你畫了控件xxxx后需要用執(zhí)行Pack來讓它顯示第61頁,共72頁。P623. Python的圖形

45、界面Python的標(biāo)準(zhǔn)圖形控件控件描述Button按鈕控件;在程序中顯示按鈕。Canvas畫布控件;顯示圖形元素如線條或文本Checkbutton多選框控件;用于在程序中提供多項(xiàng)選擇框Entry輸入控件;用于顯示簡單的文本內(nèi)容Frame框架控件;在屏幕上顯示一個(gè)矩形區(qū)域,多用來作為容器Label標(biāo)簽控件;可以顯示文本和位圖Listbox列表框控件;在Listbox窗口小部件是用來顯示一個(gè)字符串列表給用戶Menubutton菜單按鈕控件,由于顯示菜單項(xiàng)。Menu菜單控件;顯示菜單欄,下拉菜單和彈出菜單Message消息控件;用來顯示多行文本,與label比較類似Radiobutton單選按鈕控件

46、;顯示一個(gè)單選的按鈕狀態(tài)Scale范圍控件;顯示一個(gè)數(shù)值刻度,為輸出限定范圍的數(shù)字區(qū)間Scrollbar滾動(dòng)條控件,當(dāng)內(nèi)容超過可視化區(qū)域時(shí)使用,如列表框。.Text文本控件;用于顯示多行文本Toplevel容器控件;用來提供一個(gè)單獨(dú)的對(duì)話框,和Frame比較類似Spinbox輸入控件;與Entry類似,但是可以指定輸入范圍值PanedWindowPanedWindow是一個(gè)窗口布局管理的插件,可以包含一個(gè)或者多個(gè)子控件。LabelFramelabelframe 是一個(gè)簡單的容器控件。常用與復(fù)雜的窗口布局。tkMessageBox用于顯示你應(yīng)用程序的消息框。第62頁,共72頁。P634. 實(shí)現(xiàn)你

47、的第一個(gè)圖形界面import tkinterdef hello(): print(hello there)tk=tkinter.Tk()btn = tkinter.Button(tk,text=click me,command=hello,width=8,height=1) btn.pack()canvas = tkinter.Canvas(tk,width=500,height=500)canvas.pack()canvas.create_line(0, 0, 500, 500)導(dǎo)入tkinter定義一個(gè)函數(shù),在控制臺(tái)輸出hello there創(chuàng)建窗口在窗口加入按鍵,尺寸為8,1 顯示cli

48、ck 按下按鍵后執(zhí)行hello函數(shù)顯示按鍵創(chuàng)建畫布尺寸為500,500顯示畫布在畫布尺上畫一條線這是執(zhí)行結(jié)果第63頁,共72頁。P645. 常用的繪圖方法-1繪制盒子import tkinterimport randomtk=tkinter.Tk()canvas = tkinter.Canvas(tk,width=500,height=500)canvas.pack()def random_rectangle(width,height,fill_color): x1= random.randrange(width) y1= random.randrange(height) x2= x1+ran

49、dom.randrange(width) y2= y1+random.randrange(height) canvas.create_rectangle(x1,y1,x2,y2,fill=fill_color)for x in range(0,100): random_rectangle(400,400,#eb5699)第64頁,共72頁。P655. 常用的繪圖方法-2繪制圓弧import tkintertk=tkinter.Tk()canvas = tkinter.Canvas(tk,width=500,height=500)canvas.pack()canvas.create_arc(10

50、,10,200,80,extent=359,style=tkinter.ARC)canvas.create_arc(100,100,200,200,extent=359,style=tkinter.ARC)參數(shù)的意義1.圖形左上角坐標(biāo)2.圖形右下角坐標(biāo)3.繪制角度4.繪制圓弧常量第65頁,共72頁。P666. 常用的繪圖方法-3繪制多邊形import tkintertk=tkinter.Tk()canvas = tkinter.Canvas(tk,width=500,height=500)canvas.pack()canvas.create_polygon(1,1,100,10,100,110,fill=,outline=black)canvas.create_po

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論