2017-03-16 13 views
0

私は、入力のクラスラベルを返す、Pythonでk-NN​​アルゴリズムを実装しています。私が必要とするのは、クラスラベルに割り当てられたイメージを出力中に1つのウィンドウに表示することです(ウィンドウをリフレッシュすることによって)。問題は、私はGUIプログラミングに熟練していないので、まずはいくつかのリソースと支援が必要です。どの図書館、本、チュートリアルをお勧めしますか?コードの一部も高く評価されます。1つのウィンドウ(Python)の出力に基づく画像を表示

答えて

0

Turtle、PIL.ImagTk、Canvasなどの画像をプログラムに追加できるライブラリが数多くあり、Pygameを使用しても最高のパフォーマンスが得られます。

PIL.ImagTkとキャンバス:

from Tkinter import * 
from PIL import ImageTk 
backgroundImage = PhotoImage("image path (gif/PPM)") 
canvas = Canvas(width = 200, height = 200, bg = 'blue') 
canvas.pack(expand = YES, fill = BOTH) 

image = ImageTk.PhotoImage(file = "C:/Python27/programas/zimages/gato.png") 
canvas.create_image(10, 10, image = image, anchor = NW) 

mainloop() 

タートル:今

import turtle 

screen = turtle.Screen() 

# click the image icon in the top right of the code window to see 
# which images are available in this trinket 
image = "rocketship.png" 

# add the shape first then set the turtle shape 
screen.addshape(image) 
turtle.shape(image) 

screen.bgcolor("lightblue") 

move_speed = 10 
turn_speed = 10 

# these defs control the movement of our "turtle" 
def forward(): 
turtle.forward(move_speed) 

def backward(): 
    turtle.backward(move_speed) 

def left(): 
    turtle.left(turn_speed) 

def right(): 
    turtle.right(turn_speed) 

turtle.penup() 
turtle.speed(0) 
turtle.home() 

# now associate the defs from above with certain keyboard events 
screen.onkey(forward, "Up") 
screen.onkey(backward, "Down") 
screen.onkey(left, "Left") 
screen.onkey(right, "Right") 
screen.listen() 

のは、カメの背景

import turtle 

screen = turtle.Screen() 

# this assures that the size of the screen will always be 400x400 ... 
screen.setup(400, 400) 

# ... which is the same size as our image 
# now set the background to our space image 
screen.bgpic("space.jpg") 

# Or, set the shape of a turtle 
screen.addshape("rocketship.png") 
turtle.shape("rocketship.png") 

move_speed = 10 
turn_speed = 10 

# these defs control the movement of our "turtle" 
def forward(): 
    turtle.forward(move_speed) 

def backward(): 
    turtle.backward(move_speed) 

def left(): 
    turtle.left(turn_speed) 

def right(): 
    turtle.right(turn_speed) 

turtle.penup() 
turtle.speed(0) 
turtle.home() 

# now associate the defs from above with certain keyboard events 
screen.onkey(forward, "Up") 
screen.onkey(backward, "Down") 
screen.onkey(left, "Left") 
screen.onkey(right, "Right") 
screen.listen() 

を変更してみましょう: http://blog.trinket.io/using-images-in-turtle-programs/

関連する問題