- LEVEL 2
Ch.1 - Data types:
>>> Learn about data types.
>>> Learn about tuples, lists and dictionaries.
>>> Make a version of MyMagic8Ball that is much shorter to code than the one from Python Basics.
>>> Learn about data types.
>>> Learn about tuples, lists and dictionaries.
>>> Make a version of MyMagic8Ball that is much shorter to code than the one from Python Basics.
Ch.2 - Building GUIs:
>>> Practise using tuples and dictionaries.
>>> Review using tkinter and learn about some more widgets.
>>> Build a GUI.
>>> Build a glossary application that can easily be customised into a number of other simple cool apps too.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
ryGlossary_Final.py | |
查詞彙.py | |
呂仁園,2014/07/09 | |
''' | |
from tkinter import * | |
窗類= Tk | |
輸入類= Entry | |
文字類= Text | |
標籤類= Label | |
按鈕類= Button | |
# | |
# 創造 視窗應用程式的元件(widget)。 | |
# | |
窗= 窗類() | |
窗.title("查詞彙") | |
輸入框= 輸入類(窗, bg= "cyan") | |
輸出框= 文字類(窗, bg= "yellow") | |
輸入框標籤= 標籤類(窗, text= "輸入你要找的詞彙:") | |
輸出框標籤= 標籤類(窗, text= "查詢結果如下:") | |
def 點擊查詢(): | |
輸入文字= 輸入框.get() | |
try: | |
詞彙定義= 詞彙表[輸入文字] | |
# | |
# 輸入文字若在詞彙表中找不到, | |
# 程式會在此發生「意外」(except), | |
# 就進入下一行的 except: 之內。 | |
# | |
except: | |
詞彙定義 = "這個字詞 【%s】 找不到。"%(輸入文字) | |
輸出框.delete(0.0, END) | |
輸出框.insert(END, 詞彙定義) | |
按鈕= 按鈕類(窗, text= "點擊查詢", command= 點擊查詢) | |
# | |
# 安排元件的位置 | |
# | |
輸入框標籤.grid(row=0,column=0); 輸入框.grid(row=0,column=1) | |
輸出框標籤.grid(row=1,column=0); 按鈕.grid( row=1,column=1) | |
輸出框.grid( row=2,column=0, columnspan= 2) | |
# | |
# 詞彙表 資料庫 在此, | |
# 通常我們可以上網取得這種資料, | |
# 略加整理成我們要的格式。 | |
# | |
詞彙表= { | |
'台灣': 'Taiwan', | |
'美國': 'USA', | |
'日本': 'Japan', | |
'中國': 'China', | |
'Taiwan': '台灣', | |
'USA': '美國', | |
'Japan': '日本', | |
'China': '中國'} | |
# | |
# 進入主迴圈 | |
# | |
窗.mainloop() |
Ch.3 - Designing a Simple Calculator:
>>> Learn about 'for loops'.
>>> Use lists and loops to save a lot of repetitive coding.
>>> Learn more about the tkinter button widget.
>>> Design your own calculator application called MyCalculator.
>>> Build a complex GUI easily.
>>> Learn about 'for loops'.
>>> Use lists and loops to save a lot of repetitive coding.
>>> Learn more about the tkinter button widget.
>>> Design your own calculator application called MyCalculator.
>>> Build a complex GUI easily.
Ch.4 - A Fully Working Calculator:
>>> Learn how to use default values in functions creatively.
>>> Learn about debugging.
>>> Learn about catching and handling errors.
>>> Delve deeper into binary numbers.
>>> Produce a fully working calculator.
>>> Learn how to use default values in functions creatively.
>>> Learn about debugging.
>>> Learn about catching and handling errors.
>>> Delve deeper into binary numbers.
>>> Produce a fully working calculator.
Ch.5 - Customising the Calculator:
>>> Layout a customisable calculator.
>>> Create some fully functioning constant buttons.
>>> Start a module to hold the functions for our programmable buttons.
>>> Learn a little more about how to organise code in applications.
>>> Layout a customisable calculator.
>>> Create some fully functioning constant buttons.
>>> Start a module to hold the functions for our programmable buttons.
>>> Learn a little more about how to organise code in applications.
Bonus Chapter - Algorithms:
>>> Add code to the programmable buttons.
>>> Learn about algorithms.
>>> Learn about factorials.
>>> Learn how to convert numbers to roman numerals.
>>> Make a fully programmable calculator with some unique functions including its own customisable game.
>>> Add code to the programmable buttons.
>>> Learn about algorithms.
>>> Learn about factorials.
>>> Learn how to convert numbers to roman numerals.
>>> Make a fully programmable calculator with some unique functions including its own customisable game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
ryCalculator4_final.py | |
改自 myCalculator4_final.py | |
呂仁園, 2014/07/13 | |
''' | |
from math import * | |
from random import * | |
from tkinter import * | |
class 窗類(Tk): | |
def __init__(我, *x, **y): | |
Tk.__init__(我, *x, **y) | |
def 標題(我, *x, **y): | |
我.title(*x, **y) | |
def 主迴圈(我, *x, **y): | |
我.mainloop() | |
class 框類(Frame): | |
def __init__(我, *x, **y): | |
Frame.__init__(我,*x, **y) | |
def 格位(我,*x, **y): | |
我.grid(*x, **y) | |
class 鈕類(Button): | |
def __init__(我, *x, **y): | |
Button.__init__(我,*x, **y) | |
def 格位(我,*x, **y): | |
我.grid(*x, **y) | |
class 盒類(Entry): | |
def __init__(我, *x, **y): | |
Entry.__init__(我,*x, **y) | |
def 格位(我,*x, **y): | |
我.grid(*x, **y) | |
class 標類(Label): | |
def __init__(我, *x, **y): | |
Label.__init__(我,*x, **y) | |
def 格位(我,*x, **y): | |
我.grid(*x, **y) | |
class 文類(Text): | |
def __init__(我, *x, **y): | |
Text.__init__(我,*x, **y) | |
def 格位(我,*x, **y): | |
我.grid(*x, **y) | |
計數器=0 | |
def 點擊(鈕): | |
global 計數器 | |
if 鈕 == '計算': | |
try: | |
算式= 出入盒.get() | |
計算結果= eval(算式) | |
轉成文字= str(計算結果) | |
出入盒.insert(END, " 計算結果為: " + 轉成文字) | |
except: | |
出入盒.insert(END, " --> 輸入不合語法!") | |
elif 鈕 == "清除": | |
文.insert(END, '[%d:] %s\n'%(計數器, 出入盒.get())) | |
出入盒.delete(0, END) | |
計數器+=1 | |
else: | |
出入盒.insert(END, 鈕) | |
數字列表= [ str(x) for x in range(0,10)]+['.'] | |
邏輯列表= ['True', 'False', ' and ',' or ',' not '] | |
算符列表= [ | |
'(',')','+', '-','*', '/', '**', '//','%', | |
'sin(','cos(','tan(','pi','exp(','erf(', | |
'random()','randint(', | |
'==','<','<=','>','>=' | |
] | |
功能列表= ['計算','清除'] | |
列表群= [數字列表, 邏輯列表, 功能列表, 算符列表] | |
窗= 窗類() | |
窗.標題('仁園牌計算窗') | |
文= 文類(窗, bg= 'pink') | |
出入框= 框類(窗, bg= 'cyan') | |
文.格位( row= 0, column= 0, columnspan= len(列表群)) | |
出入框.格位(row= 1, column= 0, columnspan= len(列表群)) | |
col= 0 | |
for 列表 in 列表群: | |
框= 框類(窗) | |
框.格位(row= 2, column= col) | |
col+=1 | |
L= len(列表) | |
M= int(L**.5) | |
n= 0 | |
for 符 in 列表: | |
def 命令(x= 符): | |
點擊(x) | |
鈕= 鈕類(框, text= 符, width= 5, command= 命令) | |
r, c= n//M, n%M | |
n += 1 | |
鈕.格位(row= r,column= c) | |
標= 標類(出入框, bg="gray", text='出入框') | |
出入盒= 盒類(出入框, bg= "yellow") | |
標.格位( row=0, column=0) | |
出入盒.格位(row=1, column=0) | |
# | |
# 正式開跑! | |
# | |
窗.主迴圈() |
沒有留言:
張貼留言