【问题标题】:Adding and removing image Tkinter / root添加和删​​除图像 Tkinter / root
【发布时间】:2014-07-20 09:00:20
【问题描述】:

下面是我的代码。该代码来自不同的程序,因此将单击一个按钮 在另一个程序上并启动此代码。我一直在努力解决这个问题,简而言之,我正在尝试 a)拍摄图像,将其保存到目录中,b)在画布上显示图像或使用名为“刷新”。单击刷新时,删除称为删除第一次拍摄的“文件”,拍摄另一张照片并用拍摄的第二张照片刷新画布,依此类推。我似乎没有让它按这个顺序工作,并且使用了多个示例等。任何人都可以帮忙,我的设计可能不正确吗?我有足够的其他代码,但下面的代码仅详细说明了一个调用全局属性等的函数。我希望得到一个答案,但也想从答案中学习以了解做错了什么。

import os
import sys
import time
from VideoCapture import Device
impot Image
from PIL import ImageTk, Image
from Tkinter import *
import Tkinter


root = Tk()
root.wm_title("Camera Capture")
root.resizable(0,0)
root.geometry("600x400")

path = ('C:\Users\Public')
os.chdir(path)

def take_picture():
    global root
    global path
    os.chdir(path)
    cam = Device()
    cam.saveSnapshot('pic.gif')
    webcam_pic = Tkinter.PhotoImage(file='./pic.gif')
    item = Label(root, anchor = W, image = webcam_pic)
    item.pack()


button_take_picture = Button(root, text = "Take picture", command = take_picture(), bg    
=          'blue')
button_take_picture.place(relx = .9, rely = .5, anchor = "center")





mainloop()

【问题讨论】:

    标签: python image tkinter root


    【解决方案1】:

    其实这个命令应该没有这个'()'

    command =take_picture
    
    button_take_picture = Button(root, text = "Take picture", command = take_picture, bg=blue')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 2020-03-30
      • 2016-01-23
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      相关资源
      最近更新 更多