最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python交互式圖形編程實(shí)例(一)

 更新時(shí)間:2021年10月20日 17:13:43   作者:hayden__wang  
這篇文章主要為大家詳細(xì)介紹了python交互式圖形編程實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python交互式圖形編程的具體代碼,供大家參考,具體內(nèi)容如下

#!/usr/bin/env python3# -*- coding: utf-8 -*-
#溫度轉(zhuǎn)換

from graphics import *
 
win = GraphWin("攝氏溫度轉(zhuǎn)換器", 400, 300)
win.setCoords(0.0, 0.0, 3.0, 4.0)
# 繪制接口
Text(Point(1,3), " 攝氏溫度:").draw(win)
Text(Point(1,1), " 華氏溫度:").draw(win)
input = Entry(Point(2,3), 5)
input.setText("0.0")
input.draw(win)
output = Text(Point(2,1),"")
output.draw(win)
button = Text(Point(1.5,2.0),"轉(zhuǎn)換")
button.draw(win)
Rectangle(Point(1,1.5), Point(2,2.5)).draw(win)
# 等待鼠標(biāo)點(diǎn)擊
win.getMouse()
# 轉(zhuǎn)換輸入
celsius = eval(input.getText())
fahrenheit = 9.0/5.0 * celsius + 32.0
# 顯示輸出,改變按鈕
output.setText(fahrenheit)
button.setText("退出")
# 等待響應(yīng)鼠標(biāo)點(diǎn)擊,退出程序
win.getMouse()
win.close()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#方塊移動(dòng)

from tkinter import *
 
def main():  
  tk = Tk()
  canvas = Canvas(tk, width = 400, height = 400)
  canvas.pack()
 
  def moverectangle(event):
    if event.keysym == "Up":
      canvas.move(1,0,-5)
    elif event.keysym == "Down":
      canvas.move(1,0,5)
    elif event.keysym == "Left":
      canvas.move(1,-5,0)
    elif event.keysym == "Right":
      canvas.move(1,5,0)
     
  canvas.create_rectangle(180,180,220,220,fill="red")
  canvas.bind_all("<KeyPress-Up>",moverectangle)
  canvas.bind_all("<KeyPress-Down>",moverectangle)
  canvas.bind_all("<KeyPress-Left>",moverectangle)
  canvas.bind_all("<KeyPress-Right>",moverectangle)
  tk.mainloop()
 
if __name__ == '__main__':
  main()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from graphics import *

 
def convert(input):
  celsius = eval(input.getText())  # 輸入轉(zhuǎn)換
  fahrenheit = 9.0/5.0 * celsius + 32
  return fahrenheit 
def colorChange(win,input):
  cnum = eval(input.getText())
  weight = cnum / 100.0
  newcolor = color_rgb(int(255*weight),int(66+150*(1-weight)),int(255*(1-weight)))
  win.setBackground(newcolor)
def main():
  win = GraphWin("攝氏溫度轉(zhuǎn)換", 400, 300)
  win.setCoords(0.0, 0.0, 3.0, 4.0)
  # 繪制輸入接口
  Text(Point(1,3),
     " 攝氏溫度:").draw(win)
  Text(Point(2,2.7),
     " (請(qǐng)輸入: 0.0-100.0 )").draw(win)
  Text(Point(1,1),
     "華氏溫度:").draw(win)
  input = Entry(Point(2,3), 5)
  input.setText("0.0")
  input.draw(win)
  output = Text(Point(2,1),"")
  output.draw(win)
  button = Text(Point(1.5,2.0),"轉(zhuǎn)換")
  button.draw(win)
  rect = Rectangle(Point(1,1.5), Point(2,2.5))
  rect.draw(win)
  # 等待鼠標(biāo)點(diǎn)擊
  win.getMouse()
  result = convert(input)  # 轉(zhuǎn)換輸入
  output.setText(result)  # 顯示輸出 
  # 改變顏色
  colorChange(win,input)
  # 改變按鈕字體
  button.setText("退出")
  # 等待點(diǎn)擊事件,退出程序
  win.getMouse()
  win.close()
 
if __name__ == '__main__':
  main()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python3 max()函數(shù)基礎(chǔ)用法

    Python3 max()函數(shù)基礎(chǔ)用法

    在本篇文章中我們給大家講述了關(guān)于Python3 max()函數(shù)的基本用法以及相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。
    2019-02-02
  • python selenium 查找隱藏元素 自動(dòng)播放視頻功能

    python selenium 查找隱藏元素 自動(dòng)播放視頻功能

    這篇文章主要介紹了python selenium 查找隱藏元素 自動(dòng)播放視頻功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-07-07
  • 用Python爬取618當(dāng)天某東熱門(mén)商品銷(xiāo)量數(shù)據(jù),看看大家喜歡什么!

    用Python爬取618當(dāng)天某東熱門(mén)商品銷(xiāo)量數(shù)據(jù),看看大家喜歡什么!

    618購(gòu)物節(jié),準(zhǔn)備分析一波購(gòu)物節(jié)大家都喜歡買(mǎi)什么?本文以某東為例,Python爬取618活動(dòng)的暢銷(xiāo)商品數(shù)據(jù),并進(jìn)行數(shù)據(jù)清洗,最后以可視化的方式從不同角度去了解暢銷(xiāo)商品中,名列前茅的商品是哪些?銷(xiāo)售數(shù)據(jù)如何?用戶好評(píng)如何?等等,需要的朋友可以參考下
    2021-06-06
  • 淺析Python的web.py框架中url的設(shè)定方法

    淺析Python的web.py框架中url的設(shè)定方法

    web.py是Python的一個(gè)輕量級(jí)Web開(kāi)發(fā)框架,這里我們來(lái)淺析Python的web.py框架中url的設(shè)定方法,需要的朋友可以參考下
    2016-07-07
  • Pygame中畫(huà)圓弧的方法

    Pygame中畫(huà)圓弧的方法

    本文主要介紹了Pygame中畫(huà)圓弧的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • python標(biāo)準(zhǔn)庫(kù)OS模塊詳解

    python標(biāo)準(zhǔn)庫(kù)OS模塊詳解

    這篇文章主要介紹了python標(biāo)準(zhǔn)庫(kù)OS模塊詳細(xì)介紹,需要的朋友可以參考下
    2020-03-03
  • MindSpore導(dǎo)入CUDA算子的解決方案

    MindSpore導(dǎo)入CUDA算子的解決方案

    本文介紹了在MindSpore標(biāo)準(zhǔn)格式下進(jìn)行CUDA算子開(kāi)發(fā)的方法和流程,可以讓開(kāi)發(fā)者在現(xiàn)有的AI框架下仍然可以調(diào)用基于CUDA實(shí)現(xiàn)的高性能的算子,感興趣的朋友跟隨小編一起看看吧
    2024-05-05
  • python使用xpath中遇到:<Element a at 0x39a9a80>到底是什么?

    python使用xpath中遇到:<Element a at 0x39a9a80>到底是什么?

    這篇文章主要給大家詳細(xì)介紹了關(guān)于python使用xpath中遇到:<Element a at 0x39a9a80>的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • win10下python3.5.2和tensorflow安裝環(huán)境搭建教程

    win10下python3.5.2和tensorflow安裝環(huán)境搭建教程

    這篇文章主要為大家詳細(xì)介紹了win10下python3.5.2和tensorflow安裝環(huán)境搭建教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • python 實(shí)現(xiàn)矩陣上下/左右翻轉(zhuǎn),轉(zhuǎn)置的示例

    python 實(shí)現(xiàn)矩陣上下/左右翻轉(zhuǎn),轉(zhuǎn)置的示例

    今天小編就為大家分享一篇python 實(shí)現(xiàn)矩陣上下/左右翻轉(zhuǎn),轉(zhuǎn)置的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01

最新評(píng)論

济阳县| 晴隆县| 新和县| 津市市| 修武县| 固始县| 靖江市| 封丘县| 龙海市| 集贤县| 富锦市| 酒泉市| 英吉沙县| 通州市| 彩票| 汉寿县| 平遥县| 洛川县| 思茅市| 稻城县| 清徐县| 贵南县| 樟树市| 武山县| 贡嘎县| 宣恩县| 西盟| 凤山县| 晋中市| 临清市| 灵武市| 武平县| 浠水县| 宁南县| 榆林市| 元江| 农安县| 灌南县| 诸暨市| 松阳县| 繁昌县|