欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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()

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

相關(guān)文章

  • django xadmin中form_layout添加字段顯示方式

    django xadmin中form_layout添加字段顯示方式

    這篇文章主要介紹了django xadmin中form_layout添加字段顯示方式,具有很好的 參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • CentOS 6.5中安裝Python 3.6.2的方法步驟

    CentOS 6.5中安裝Python 3.6.2的方法步驟

    centos 6.5默認(rèn)自帶的python版本為2.6,而下面這篇文章主要給大家介紹了關(guān)于在CentOS 6.5中安裝Python 3.6.2的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • Django中自定義查詢對(duì)象的具體使用

    Django中自定義查詢對(duì)象的具體使用

    這篇文章主要介紹了Django中自定義查詢對(duì)象的具體使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • 簡單談?wù)凱ython中的元祖(Tuple)和字典(Dict)

    簡單談?wù)凱ython中的元祖(Tuple)和字典(Dict)

    這篇文章主要介紹了關(guān)于Python中元祖(Tuple)和字典(Dict)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。
    2017-04-04
  • Django零基礎(chǔ)入門之運(yùn)行Django版的hello world

    Django零基礎(chǔ)入門之運(yùn)行Django版的hello world

    這篇文章主要介紹了Django零基礎(chǔ)入門之運(yùn)行Django版的hello world,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09
  • Python實(shí)現(xiàn)柵欄密碼的加密解密方法詳解

    Python實(shí)現(xiàn)柵欄密碼的加密解密方法詳解

    這篇文章主要介紹了Python實(shí)現(xiàn)柵欄密碼的加密解密方法,所謂柵欄密碼,就是把要加密的明文分成N個(gè)一組,然后把每組的第1個(gè)字連起來,形成一段無規(guī)律的話。不過柵欄密碼本身有一個(gè)潛規(guī)則,就是組成柵欄的字母一般不會(huì)太多
    2023-01-01
  • 詳解python如何在django中為用戶模型添加自定義權(quán)限

    詳解python如何在django中為用戶模型添加自定義權(quán)限

    這篇文章主要介紹了python如何在django中為用戶模型添加自定義權(quán)限,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-10-10
  • python實(shí)現(xiàn)時(shí)間序列自相關(guān)圖(acf)、偏自相關(guān)圖(pacf)教程

    python實(shí)現(xiàn)時(shí)間序列自相關(guān)圖(acf)、偏自相關(guān)圖(pacf)教程

    這篇文章主要介紹了python實(shí)現(xiàn)時(shí)間序列自相關(guān)圖(acf)、偏自相關(guān)圖(pacf)教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • python高階函數(shù)functools模塊的具體使用

    python高階函數(shù)functools模塊的具體使用

    本文主要介紹了python高階函數(shù)functools模塊的具體使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • python實(shí)現(xiàn)通訊錄系統(tǒng)

    python實(shí)現(xiàn)通訊錄系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)通訊錄系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05

最新評(píng)論