Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 基于一个窗口中的输出显示图像(Python)_Python 3.x_User Interface - Fatal编程技术网

Python 3.x 基于一个窗口中的输出显示图像(Python)

Python 3.x 基于一个窗口中的输出显示图像(Python),python-3.x,user-interface,Python 3.x,User Interface,我在Python中实现了k-NN算法,它返回输入的类标签。我需要的是在输出到来时(通过刷新窗口),在一个窗口中显示分配给类标签的图像。问题是,我在GUI编程方面不是很有经验,所以我需要一些资源和帮助。你可以推荐哪些图书馆、书籍和教程?代码片段也会很受欢迎。有许多库允许您将图像添加到程序中,如Turtle、PIL.ImagTk和Canvas,您甚至可以使用Pygame获得最佳性能 PIL.ImagTk和Canvas: from Tkinter import * from PIL import Im

我在Python中实现了k-NN算法,它返回输入的类标签。我需要的是在输出到来时(通过刷新窗口),在一个窗口中显示分配给类标签的图像。问题是,我在GUI编程方面不是很有经验,所以我需要一些资源和帮助。你可以推荐哪些图书馆、书籍和教程?代码片段也会很受欢迎。

有许多库允许您将图像添加到程序中,如Turtle、PIL.ImagTk和Canvas,您甚至可以使用Pygame获得最佳性能

PIL.ImagTk和Canvas:

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()
对于海龟: