SlideShare a Scribd company logo
1 of 23
Python講座第4回
参考資料
前回の復習
反復構造(While)
While 条件式 or 真偽値:
[中身(実行するプログラム)]
• 条件式 or 真偽値がTrue(真)である限り[中身]を繰り返す
• 条件式 or 真偽値がFalse(偽)になったときは[中身]を実行しない
もしくは実行していた場合は抜ける
関数(def)
def [関数名(自由)](引数,引数,…):
[中身(実行するプログラム)]
return [返す値] #返す値があるときのみ
繰り返し使う動作を一つにまとめられる
• 記述量を減らせる
• ミス(バグ)があった際に直す箇所が集約されているの
で直しやすい
グラフィックス
グラフィカルユーザーインターフェース(GUI)
ユーザーに視覚的に分かりやすい(グラフィカルな)UIを提供する
CUI GUI
標準で入っているGUIライブラリ
• turtle
• Tkinter(Tk)
turtle
turtle
ペンでお絵描きすることができる!
使える関数 動作
t.penup() ペン先をキャンバス
から離す
t.pendown() ペン先をキャンバス
に置く
t.setpos(x, y) 任意の座標まで移動
する
t.pencolor('red') 線の色を変更する
t.pensize(3) 線の太さを変更する
t.write('hello!') 現在位置のすぐ上に
文字列を描画
使える関数 動作
t.forward(10) 現在の向きに10距離前進
する
t.left(10) 10度左に向きを変える
t.right(10) 10度右に向きを変える
t.circle(50,240) 回転半径50で270度の円
弧を描くように進む
turtle
import turtle
t = turtle.Turtle()
t.color("blue")
t.pendown() # ペンを下す
t.forward(100) # 100進む
t.penup() # ペンを上げる
t.setpos(10, 10) # ペン先を
(10,10)に移動
t.pendown() # ペンを下す
t.setpos(50, 50) # ペン先を
(50,50)に移動
t.left(90) # 90度左回転
t.forward(100) # 100進む
t.shape("turtle") # 形を亀に変更
t.right(180) # 右に180度回転
t.forward(100) # 100進む
turtle._Screen.mainloop(turtle)
turtle.exitonclick()
turtleを使えるよ
うにするおまじない
IDLE以外では記述
しとかないと表示を
維持できない
座標について
正三角形を描こう!
角度について
正五角形を描こう!
Tkinter(Tk)
Tkinter
手軽にGUIアプリケーションが作れる!
ButtonやLabel,Canvas,Frameなど多くの機能を備える
from tkinter import *
tk = Tk()
Tkinterを使うためのおまじない笑
ウィンドウの表示
from tkinter import *
tk=Tk()
canvas=Canvas(tk, width=500, height=500) #500×500のウィンドウを作成
canvas.pack()
canvas2 = Canvas(tk2) # ウィンドウサイズ指定なし
canvas2.pack()
pack()しないとウィンドウ上に何も表示されない
ウィンドウの表示
Tkinter
表示維持に必要!(IDLE以外)
mainloop()
座標について
正三角形を描こう!
家を描こう!
グラフを描こう!

More Related Content

Featured

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Python講座 2018 第4回

Editor's Notes

  1. CUIはキャラクターユーザーインターフェース GUIはグラフィカルユーザーインターフェース
  2. もし,IDLE以外を使用している場合は実行終了とともにウィンドウが閉じてしまう。 その場合は,turtle._Screen.mainloop(turtle)かturtle.exitonclick()をプログラムの最後に追記しておきましょう
  3. 矢印の先が向いている向き。そこを基準として角度が決まります。
  4. いっぱい機能はあるけど,法政大学ではCanvasくらいしか使わないので,Canvasのみ扱います。
  5. 初期値があるので,width=などは記載せずともウィンドウは生成される。
  6. いっぱい機能はあるけど,法政大学ではCanvasくらいしか使わないので,Canvasのみ扱います。