Beispiel #1
0
 def __init__(self, imgdir, imgfile):
     Toplevel.__init__(self)
     self.title(imgfile)
     imgpath = os.path.join(imgdir, imgfile)
     imgobj  = PhotoImage(file=imgpath)
     Label(self, image=imgobj).pack( )
     print imgpath, imgobj.width(), imgobj.height( )   # size in pixels
     self.savephoto = imgobj                           # keep reference on me
Beispiel #2
0
 def __init__(self, imgdir, imgfile):
     Toplevel.__init__(self)
     self.title(imgfile)
     imgpath = os.path.join(imgdir, imgfile)
     imgobj = PhotoImage(file=imgpath)
     Label(self, image=imgobj).pack()
     print imgpath, imgobj.width(), imgobj.height()  # size in pixels
     self.savephoto = imgobj  # keep reference on me
Beispiel #3
0
def get_image():
    global img_camera, img_modified
    i = c.get_photo().get_response().resize((100, 100), Img.ANTIALIAS)
    reduce_noise(i)

    img = PhotoImage(i)
    img_camera.configure(image=img)
    img_camera.img = img

    img_m = PhotoImage(filter_red(i))
    img_modified.configure(image=img_m)
    img_modified.img = img_m

    img_camera.after(100, get_image)
Beispiel #4
0
def viewer(imgdir, kind=Toplevel, cols=None):
    """
    make thumb links window for an image directory:
    one thumb button per image; use kind=Tk to show
    in main  app window, or Frame container (pack);
    imgfile differs per loop: must save with a default;
    photoimage objs must be saved: erased if reclaimed;
    """
    win = kind()
    win.title('Viewer: ' + imgdir)
    thumbs = makeThumbs(imgdir)
    if not cols:
        cols = int(math.ceil(math.sqrt(len(thumbs))))  # fixed or N x N

    savephotos = []
    while thumbs:
        thumbsrow, thumbs = thumbs[:cols], thumbs[cols:]
        row = Frame(win)
        row.pack(fill=BOTH)
        for (imgfile, imgobj) in thumbsrow:
            photo = PhotoImage(imgobj)
            link = Button(row, image=photo)
            handler = lambda savefile=imgfile: ViewOne(imgdir, savefile)
            link.config(command=handler)
            link.pack(side=LEFT, expand=YES)
            savephotos.append(photo)

    Button(win, text='Quit', command=win.quit).pack(fill=X)
    return win, savephotos
Beispiel #5
0
def viewer(imgdir, kind=Toplevel, cols=None):
    """
    custom version that uses gridding
    """
    win = kind()
    win.title('Viewer: ' + imgdir)
    thumbs = makeThumbs(imgdir)
    if not cols:
        cols = int(math.ceil(math.sqrt(len(thumbs))))  # fixed or N x N

    rownum = 0
    savephotos = []
    while thumbs:
        thumbsrow, thumbs = thumbs[:cols], thumbs[cols:]
        colnum = 0
        for (imgfile, imgobj) in thumbsrow:
            photo = PhotoImage(imgobj)
            link = Button(win, image=photo)
            handler = lambda savefile=imgfile: ViewOne(imgdir, savefile)
            link.config(command=handler)
            link.grid(row=rownum, column=colnum)
            savephotos.append(photo)
            colnum += 1
        rownum += 1

    Button(win, text='Quit', command=win.quit).grid(columnspan=cols, stick=EW)
    return win, savephotos
def show_photo():
    # Get the photo
    img = c.get_photo() \
        .get_response() \
        .resize((300, 300), Img.ANTIALIAS)

    # Convert the photo for OpenCV
    cv_img = cv.CreateImageHeader(img.size, cv.IPL_DEPTH_8U, 1)
    cv.SetData(cv_img, img.tostring())

    # Find any faces in the image
    storage = cv.CreateMemStorage(0)
    cv.EqualizeHist(cv_img, cv_img)
    faces = cv.HaarDetectObjects(cv_img, cascade, storage, 1.2, 2,
                                 cv.CV_HAAR_DO_CANNY_PRUNING)

    if faces:
        for f in faces:
            # Draw a border around a found face.
            draw = ImageDraw.Draw(img)
            draw.setfill(0)
            draw.rectangle([(f[0][0], f[0][1]),
                            (f[0][0] + f[0][2], f[0][1] + f[0][3])])

    image = PhotoImage(img)
    img_face.config(image=image)
    img_face.img = image

    img_face.after(10, show_photo)
def viewer(imgdir, kind=Toplevel, cols=None):
    """
    custom version that lays out with fixed-size buttons
    """
    win = kind()
    win.title('Viewer: ' + imgdir)
    thumbs = makeThumbs(imgdir)
    if not cols: 
        cols = int(math.ceil(math.sqrt(len(thumbs))))     # fixed or N x N

    savephotos = []
    while thumbs:
        thumbsrow, thumbs = thumbs[:cols], thumbs[cols:]
        row = Frame(win)
        row.pack(fill=BOTH)
        for (imgfile, imgobj) in thumbsrow:
            size    = max(imgobj.size)                     # width, height
            photo   = PhotoImage(imgobj)
            link    = Button(row, image=photo)
            handler = lambda savefile=imgfile: ViewOne(imgdir, savefile)
            link.config(command=handler, width=size, height=size)
            link.pack(side=LEFT, expand=YES)
            savephotos.append(photo)

    Button(win, text='Quit', command=win.quit, bg='beige').pack(fill=X)
    return win, savephotos
Beispiel #8
0
def viewThumbs(imgdir, kind=Toplevel, numcols=None, height=400, width=500):
    """
    make main or popup thumbnail buttons window;
    uses fixed-size buttons, scrollable canvas;
    sets scrollable (full) size, and places
    thumbs at abs x,y coordinates in canvas;
    no longer assumes all thumbs are same size:
    gets max of all (x,y), some may be smaller;
    """
    win = kind()
    helptxt = '(press D to open other)'
    win.title(appname + imgdir + '  ' + helptxt)
    quit = Button(win, text='Quit', command=win.quit, bg='beige')
    quit.pack(side=BOTTOM, fill=X)
    canvas = ScrolledCanvas(win)
    canvas.config(height=height, width=width)  # init viewable window size
    # changes if user resizes
    thumbs = makeThumbs(imgdir)  # [(imgfile, imgobj)]
    numthumbs = len(thumbs)
    if not numcols:
        numcols = int(math.ceil(math.sqrt(numthumbs)))  # fixed or N x N
    numrows = int(math.ceil(numthumbs / float(numcols)))

    # thumb=(name, obj), thumb.size=(width, height)
    linksize = max([max(thumb[1].size) for thumb in thumbs])
    print linksize
    fullsize = (
        0,
        0,  # upper left  X,Y
        (linksize * numcols),
        (linksize * numrows))  # lower right X,Y
    canvas.config(scrollregion=fullsize)  # scrollable area size

    rowpos = 0
    savephotos = []
    while thumbs:
        thumbsrow, thumbs = thumbs[:numcols], thumbs[numcols:]
        colpos = 0
        for (imgfile, imgobj) in thumbsrow:
            photo = PhotoImage(imgobj)
            link = Button(canvas, image=photo)
            handler = (lambda savefile=imgfile: ViewOne(imgdir, savefile))
            link.config(command=handler, width=linksize, height=linksize)
            link.pack(side=LEFT, expand=YES)
            canvas.create_window(colpos,
                                 rowpos,
                                 anchor=NW,
                                 window=link,
                                 width=linksize,
                                 height=linksize)
            colpos += linksize
            savephotos.append(photo)
        rowpos += linksize
    win.bind('<KeyPress-d>', onDirectoryOpen)
    win.savephotos = savephotos
    return win
Beispiel #9
0
    def __init__(self):
        self.root = root = Tk()
        root.withdraw()    #hide window
        root.title('Tk Post Tool')
        screen_width = root.winfo_screenwidth()
        screen_height = root.winfo_screenheight() - 100    #a taskbar may lie under the screen
        root.resizable(False,False)

        from ImageTk import PhotoImage
        icon = PhotoImage(file='1.jpg')
        root.tk.call('wm', 'iconphoto', root._w, icon)

        Label(root, text='URL').grid(row=0, column=0, sticky=NW, padx=10, pady=10)
        self.txtURL = txtURL = Entry(root)
        txtURL.grid(row=0, column=1, sticky=EW)
        txtURL.focus_set()
        
        Label(root, text='Headers').grid(row=1, column=0, sticky=NW, padx=10)
        headers_bar = Scrollbar()
        self.txtHeaders = txtHeaders = Text(root, bg='#F5F5DC', yscrollcommand=headers_bar.set)
        txtHeaders.grid(row=1, column=1, sticky=W)
        txtHeaders.config(width=60, height=4)
        headers_bar.grid(row=1, column=2, sticky=NS)
        headers_bar.config(command=txtHeaders.yview)
        txtHeaders.insert(END,headers)
        txtHeaders.grid_columnconfigure(2, weight=1)
        
        Label(root, text='Form Data').grid(row=2, column=0, sticky=NW, padx=20, pady=20)
        data_bar = Scrollbar()
        self.txtData = txtData = Text(root, bg='#FAEBD7', yscrollcommand=data_bar.set)
        txtData.grid(row=2, column=1, sticky=W, pady=15)
        txtData.config(width=60, height=3)
        data_bar.grid(row=2, column=2, sticky=NS, pady=15)
        data_bar.config(command=txtData.yview)

        self.cmdPost = cmdPost = Button(root, text='Post', bg='#FFDEAD', width=15, command=lambda: self.cmd_click(self))
        cmdPost.grid(row=3, column=1, sticky=W)
        
        Label(root, text='Reponse').grid(row=4, column=0, sticky=NW, padx=10, pady=10)
        html_bar = Scrollbar()
        self.txtHTML = txtHTML = Text(root, yscrollcommand=html_bar.set)
        txtHTML.grid(row=4, column=1, pady=10)
        txtHTML.config(width=60, height=9)
        txtHTML.insert('end', copyright)
        txtHTML.tag_add("title", '1.0', txtHTML.index("1.0 lineend"))    #set font weight bold for title
        txtHTML.tag_configure('title', font='helvetica 12 bold')
        html_bar.grid(row=4, column=2, sticky=NS, pady=10)
        html_bar.config(command=txtHTML.yview)

        root.update_idletasks()
        root.deiconify()    #calculate window size
        root.withdraw()     #hide it
        #put it on screen center
        root.geometry('%sx%s+%s+%s' % (root.winfo_width() + 10, root.winfo_height(),
                                       (screen_width - root.winfo_width())/2, (screen_height - root.winfo_height())/2) )
        root.deiconify()
Beispiel #10
0
 def makeObject(self, item, px, py):
     x, y = px * 50, py * 50
     im = Image.open("../images/%s.gif" % item.lower())
     im = im.resize((48, 48), Image.BILINEAR)
     image = PhotoImage(im)
     self.canvas.create_image(x + 2, y + 2, anchor=tk.NW, image=image)
     for obj in self.env.object_classes:
         if obj.__name__ == item:
             self.env.add_object(obj(image), (px, py))
             return
Beispiel #11
0
    def __init__(self):
        self.root = root = Tk()
        root.withdraw()  #hide window
        root.title('Tk Post Tool')  # 标题内容
        screen_width = root.winfo_screenwidth()
        screen_height = root.winfo_screenheight(
        ) - 100  #a taskbar may lie under the screen
        root.resizable(False, False)

        from ImageTk import PhotoImage
        icon = PhotoImage(file='icon.gif')
        root.tk.call('wm', 'iconphoto', root._w, icon)

        Label(root, text='(→_→)').grid(row=2,
                                       column=0,
                                       sticky=NW,
                                       padx=10,
                                       pady=10)
        data_bar = Scrollbar()

        self.txtData = txtData = Text(root,
                                      bg='#FAEBD7',
                                      yscrollcommand=data_bar.set)
        txtData.grid(row=2, column=1, sticky=W, pady=15)
        txtData.config(width=60, height=30)
        data_bar.grid(row=2, column=2, sticky=NS, pady=15)
        txtData.focus_set()
        #data_bar.config(command=txtData.yview)

        self.cmdPost = cmdPost = Button(root,
                                        text='GO',
                                        bg='#FFDEAD',
                                        width=15,
                                        command=lambda: self.cmd_click(self))
        cmdPost.grid(row=3, column=1, sticky=NW)

        self.cmdShow = cmdShow = Button(root,
                                        text='(░)',
                                        bg='#FFDEAD',
                                        width=2,
                                        command=lambda: self.cmd_show(self))
        cmdShow.grid(
            row=3,
            column=2,
        )

        root.update_idletasks()
        root.deiconify()  #calculate window size
        root.withdraw()  #hide it
        #put it on screen center
        root.geometry('%sx%s+%s+%s' %
                      (root.winfo_width() + 10, root.winfo_height(),
                       (screen_width - root.winfo_width()) / 2,
                       (screen_height - root.winfo_height()) / 2))
        root.deiconify()
Beispiel #12
0
    def __init__(self):
        self.root = root = Tk()
        root.withdraw()
        root.title(u'吉敏豆瓣音乐下载工具 4.0')
        self.screen_width = screen_width = root.winfo_screenwidth()
        self.screen_height = screen_height = root.winfo_screenheight() - 100
        root.resizable(False,False)

        self.icon = icon = PhotoImage(file='icon.gif')
        root.tk.call('wm', 'iconphoto', root._w, icon)
        Label(root, text=u'请悉知', foreground='brown'
              ).grid(row=0, sticky=E, padx=5, pady=10)
        Label(root, text=u'这是一个收费工具,试用时您可以下载\n红心兆赫前50首, 专辑前3首, 小站前10首.',
              foreground='brown', justify=LEFT).grid(row=0, column=1, sticky=W, pady=10)
        Label(root, text=u'程序需要访问您的红心歌曲,请登录豆瓣 ...'
              ).grid(row=1, column=1, sticky=W, pady=0)
        
        Label(root, text=u'用户名').grid(row=2, column=0, sticky=NW, padx=10, pady=10)
        self.txtUser = Entry(width=30)
        self.txtUser.grid(row=2, column=1, sticky=W, pady=10)
        self.txtUser.focus_set()
        Label(root, text=u'密 码').grid(row=3, column=0, sticky=NW, padx=10, pady=5)
        self.txtPass = Entry(width=30, show='*')
        self.txtPass.grid(row=3, column=1, sticky=W, pady=10)
        
        Label(root, text=u'验证码').grid(row=4, column=0, sticky=NW, padx=10, pady=5)
        self.txtCAPTCHA = Entry(width=30)
        self.txtCAPTCHA.grid(row=4, column=1, sticky=W, pady=5)
        self.txtCAPTCHA.bind('<Return>', self.cmd_login)
        
        self.lbl_CAPTCHA = Label(text=u'正在加载 ...', width=20, height=4, justify=LEFT)
        self.lbl_CAPTCHA.grid(row=5, column=1, sticky=NW, pady=5)

        self.cmdLogin = Button(root, text=u'登 录', state=DISABLED, width=5,
                               command=lambda:self.cmd_login(self))
        self.cmdLogin.grid(row=6, column=1, sticky=W, pady=5)
        self.cmdLogin.bind('<Return>', self.cmd_login)
        
        self.cmdBuy = Button(root, text=u'购 买',
                             width=5, justify=RIGHT, command=lambda: self.cmd_buy(self))
        self.cmdBuy.grid(row=6, column=1, sticky=E, padx=30, pady=10)

        root.update_idletasks()
        root.deiconify()
        root.withdraw()
        root.geometry('%sx%s+%s+%s' % (root.winfo_width() + 10, root.winfo_height(),
                                       (screen_width - root.winfo_width())/2,
                                       (screen_height - root.winfo_height())/2) )
        root.deiconify()
        root.wm_protocol('WM_DELETE_WINDOW', self.on_quit)
        self.DEAD = False
Beispiel #13
0
    def drawImage(self, imgpil, forcesize=( )):
        imgtk = PhotoImage(image=imgpil)                  # not file=imgpath
        scrwide, scrhigh = forcesize or self.maxsize( )   # wm screen size x,y
        imgwide  = imgtk.width( )                         # size in pixels
        imghigh  = imgtk.height( )                        # same as imgpil.size

        fullsize = (0, 0, imgwide, imghigh)              # scrollable
        viewwide = min(imgwide, scrwide)                 # viewable
        viewhigh = min(imghigh, scrhigh)

        canvas = self.canvas
        canvas.delete('all')                             # clear prior photo
        canvas.config(height=viewhigh, width=viewwide)   # viewable window size
        canvas.config(scrollregion=fullsize)             # scrollable area size
        canvas.create_image(0, 0, image=imgtk, anchor=NW)

        if imgwide <= scrwide and imghigh <= scrhigh:    # too big for display?
            self.state('normal')                         # no: win size per img
        elif sys.platform[:3] == 'win':                  # do windows fullscreen
            self.state('zoomed')                         # others use geometry( )
        self.saveimage = imgpil
        self.savephoto = imgtk                           # keep reference on me
        print (scrwide, scrhigh), imgpil.size
Beispiel #14
0
    def drawImage(self, imgpil, forcesize=()):
        imgtk = PhotoImage(image=imgpil)  # not file=imgpath
        scrwide, scrhigh = forcesize or self.maxsize()  # wm screen size x,y
        imgwide = imgtk.width()  # size in pixels
        imghigh = imgtk.height()  # same as imgpil.size

        fullsize = (0, 0, imgwide, imghigh)  # scrollable
        viewwide = min(imgwide, scrwide)  # viewable
        viewhigh = min(imghigh, scrhigh)

        canvas = self.canvas
        canvas.delete('all')  # clear prior photo
        canvas.config(height=viewhigh, width=viewwide)  # viewable window size
        canvas.config(scrollregion=fullsize)  # scrollable area size
        canvas.create_image(0, 0, image=imgtk, anchor=NW)

        if imgwide <= scrwide and imghigh <= scrhigh:  # too big for display?
            self.state('normal')  # no: win size per img
        elif sys.platform[:3] == 'win':  # do windows fullscreen
            self.state('zoomed')  # others use geometry()
        self.saveimage = imgpil
        self.savephoto = imgtk  # keep reference on me
        print(scrwide, scrhigh), imgpil.size
Beispiel #15
0
    def set_image(self, current_image):
        self.orginal_img.image = current_image

        self.orginal_img.photo = PhotoImage(self.orginal_img.image)

        self.orginal_img.create_image(0,
                                      0,
                                      image=self.orginal_img.photo,
                                      anchor='nw',
                                      tags='img')

        w, h = self.orginal_img.image.size
        self.orginal_img.config(width=w,
                                height=h,
                                scrollregion=self.orginal_img.bbox('all'))
Beispiel #16
0
    def nextImm(self, c, event=None):
        self.img1.pack_forget()
        self.ima = Image.open(self.plist[c] + self.flist[c])
        self.ima = self.ima.resize((600, 600), Image.ANTIALIAS)
        self.display_img = PhotoImage(self.ima)

        self.img1 = Label(self.frame,
                          image=self.display_img,
                          width=600,
                          height=600,
                          anchor=CENTER)
        self.img1.image = self.display_img
        self.img1.pack(anchor=CENTER)

        self.root.update()
Beispiel #17
0
class Downloader(ToolGUI):
    def __init__(self):
        ToolGUI.__init__(self)
        self.busy_slaves = 0
        self.lock = threading.Lock()

    def slave_enter(self):  # Working
        self.lock.acquire()
        self.busy_slaves += 1
        self.lock.release()

    def slave_exit(self):  # Done
        self.lock.acquire()
        self.busy_slaves -= 1
        self.lock.release()

    def downCAPTCHA(self):
        self.cookie = cookielib.CookieJar()
        self.opener = urllib2.build_opener(
            urllib2.HTTPCookieProcessor(self.cookie))
        self.opener.addheaders = [
            ('User-Agent', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 \
                                   (KHTML, like Gecko) Chrome/31.0.1650.48 Safari/537.36'
             )
        ]
        urllib2.install_opener(self.opener)
        while True and not self.DEAD:
            try:
                self.CAPTCHA_id = CAPTCHA_id = urllib2.urlopen(
                    'http://douban.fm/j/new_captcha').read().strip('"')
                break
            except Exception, e:
                self.lbl_CAPTCHA.config(text=u'无法获取验证码...\n' + str(e))
                time.sleep(1)
        with open('CAPTCHA.jpg', 'wb') as outFile:
            outFile.write(
                urllib2.urlopen(
                    'http://www.douban.com/misc/captcha?size=m&id=' +
                    CAPTCHA_id).read())
        self.lbl_CAPTCHA.image = CAPTCHA_img = PhotoImage(file='CAPTCHA.jpg')
        self.lbl_CAPTCHA.config(text='',
                                image=CAPTCHA_img,
                                width=220,
                                height=60)  # Pic width: 220px, height:60px
        self.root.after(10, self.lbl_CAPTCHA.update_idletasks)
        self.cmdLogin.config(state='normal')
        return
Beispiel #18
0
def show_frame():
    global frame2
    global c
    global b
    ret, frame = cap.read()
    yedekframe = frame
    if a % 2 == 0:
        frame2 = cv2.flip(frame, 1)
    if b > c:
        fname = name + str(b) + tur
        cv2.imwrite(fname, frame2)
        c = b
    cv2image = cv2.cvtColor(frame2, cv2.COLOR_BGR2RGB)
    img = Image.fromarray(cv2image)
    imgtk = PhotoImage(image=img)
    lmain.imgtk = imgtk
    lmain.configure(image=imgtk)
    lmain.after(10, show_frame)
Beispiel #19
0
 def _observer_scrolledlist(self, selection):
     self.logger.debug("_observer_scrolledlist called with: %s" % selection)
     p = self.current_files_hash[selection]
     if os.path.splitext(p)[1] in SUPPORTED_FILES:
         img = Image.open(p)
         if img.size[0] > 400:
             img = img.resize((400, 300))
         self.img = PhotoImage(image=img)
         self.image_canvas.delete('all')
         self.image_canvas.create_image(20, 5, image=self.img, anchor=NW)
         self.canvaslabel_text.set(_('Picture: %s' % p))
         self.text_entry.delete(1.0, END)
         self.texttitle.delete(0, END)
         self.current_selection = selection
         if self.xml_hash.has_key(self.current_selection):
             self.texttitle.insert(
                 0, self.xml_hash[self.current_selection]['title'])
             self.text_entry.insert(
                 1.0, self.xml_hash[self.current_selection]['text'])
Beispiel #20
0
def nextimm():

    global c
    global img1

    img1.pack_forget()

    #print path_list[c] + file_list[c]

    ima = Image.open(path_list[c] + file_list[c])
    ima = ima.resize((600, 600), Image.ANTIALIAS)
    display_img = PhotoImage(ima)

    img1 = Label(mainframe,
                 image=display_img,
                 width=600,
                 height=600,
                 anchor=CENTER)
    img1.image = display_img
    img1.pack(anchor=CENTER)
Beispiel #21
0
    def __init__(self, copydir, files, paths, c=0):
        Fullscreen_Window.__init__(self)

        self.plist = paths
        self.flist = files
        self.dir = copydir

        self.ima = Image.open(paths[c] + files[c])
        self.ima = self.ima.resize((600, 600), Image.ANTIALIAS)
        self.display_img = PhotoImage(self.ima)

        self.img1 = Label(self.frame,
                          image=self.display_img,
                          width=600,
                          height=600,
                          anchor=CENTER)
        self.img1.image = self.display_img
        self.img1.pack(anchor=CENTER)

        self.root.bind("<k>", self.keepImm)
        self.root.bind("<d>", self.delImm)
        self.root.bind("<z>", self.annulla)
Beispiel #22
0
 def set_classified_image(self, img):
     self.classified_img.image = img
     photo = PhotoImage(self.classified_img.image)
     self.classified_img.configure(image=photo)
     self.classified_img.photo = photo
Beispiel #23
0
#######################################################
# show one image with PIL photo replacement object
# install PIL first: placed in Lib\site-packages
#######################################################

import os, sys
from Tkinter import *
from ImageTk import PhotoImage           # <== use PIL replacement class
                                         # rest of code unchanged
imgdir  = 'C:\gifs\\'
imgfile = 'newmarket-uk-1.jpg'
if len(sys.argv) > 1:
    imgfile = sys.argv[1]
imgpath = os.path.join(imgdir, imgfile)

win = Tk( )
win.title(imgfile)
imgobj = PhotoImage(file=imgpath)        # now JPEGs work!
Label(win, image=imgobj).pack( )
win.mainloop( )
print imgobj.width(), imgobj.height( )    # show size in pixels on exit

Beispiel #24
0
#  -*- coding:utf-8 -*-

import sys, os
try:
    import tkinter as tk
    import tkinter.ttk as ttk
except:
    import Tkinter as tk
    import ttk

from ImageTk import PhotoImage





root = tk.Tk()
w = tk.Label(root, text="Hello, world!")
w.pack()
root.title("My Application")
root.geometry('800x600')
root.wm_title("智能路灯集控 V1.1       扬州天恒出品")
img = PhotoImage(file='logo_32x32.ico')
root.tk.call('wm', 'iconphoto', root._w, img)
root.mainloop()
Beispiel #25
0
import os, sys
from Tkinter import *
from ImageTk import PhotoImage              # <== required for JPEGs and others

imgdir = 'C:\gifs\\'
if len(sys.argv) > 1: imgdir = sys.argv[1]
imgfiles = os.listdir(imgdir)               # does not include directory prefix

main = Tk( )
main.title('Viewer')
quit = Button(main, text='Quit all', command=main.quit, font=('courier', 25))
quit.pack( )
savephotos = []

for imgfile in imgfiles:
    imgpath = os.path.join(imgdir, imgfile)
    win = Toplevel( )
    win.title(imgfile)
    try:
        imgobj = PhotoImage(file=imgpath)
        Label(win, image=imgobj).pack( )
        print imgpath, imgobj.width(), imgobj.height( )       # size in pixels
        savephotos.append(imgobj)                              # keep a reference
    except:
        errmsg = 'skipping %s\n%s' % (imgfile, sys.exc_info( )[1])
        Label(win, text=errmsg).pack( )

main.mainloop( )

Beispiel #26
0
#######################################################

import os, sys
from Tkinter import *
from ImageTk import PhotoImage  # <== required for jpegs and others

imgdir = 'images'
if len(sys.argv) > 1: imgdir = sys.argv[1]
imgfiles = os.listdir(imgdir)  # does not include directory prefix

main = Tk()
main.title('Viewer')
quit = Button(main, text='Quit all', command=main.quit, font=('courier', 25))
quit.pack()
savephotos = []

for imgfile in imgfiles:
    imgpath = os.path.join(imgdir, imgfile)
    win = Toplevel()
    win.title(imgfile)
    try:
        imgobj = PhotoImage(file=imgpath)
        Label(win, image=imgobj).pack()
        print imgpath, imgobj.width(), imgobj.height()  # size in pixels
        savephotos.append(imgobj)  # keep a reference
    except:
        errmsg = 'skipping %s\n%s' % (imgfile, sys.exc_info()[1])
        Label(win, text=errmsg).pack()

main.mainloop()
Beispiel #27
0
def update_img(container, img_stream):
    img = PhotoImage(Image.open(img_stream))
    container.configure(image = img)
    container.image = img
Beispiel #28
0
#######################################################
# show one image with PIL photo replacement object
# install PIL first: placed in Lib\site-packages
#######################################################

import os, sys
from Tkinter import *
from ImageTk import PhotoImage  # <== use PIL replacement class
# rest of code unchanged
imgdir = 'C:\gifs\\'
imgfile = 'newmarket-uk-1.jpg'
if len(sys.argv) > 1:
    imgfile = sys.argv[1]
imgpath = os.path.join(imgdir, imgfile)

win = Tk()
win.title(imgfile)
imgobj = PhotoImage(file=imgpath)  # now JPEGs work!
Label(win, image=imgobj).pack()
win.mainloop()
print imgobj.width(), imgobj.height()  # show size in pixels on exit
Beispiel #29
0
  def __init__(self,filestr):
    self.loop_flag = 0
    self.delay_value = 0.0
    self.delay_msec = 0

    # convert filestr into full list of files
    
    list = str.split(filestr)
    self.files = []
    for file in list: self.files += glob.glob(file)
    self.nframes = len(self.files)
    if self.nframes == 0: raise StandardError, "No files to load"

    # load all images
    
    self.images = []
    for i in xrange(self.nframes):
      self.images.append(PhotoImage(file=self.files[i]))

    # grab Tk instance from main
    
    from __main__ import tkroot
    self.tkroot = tkroot

    # GUI control window
    
    win1 = Toplevel(tkroot)
    win1.title("Pizza.py animate tool")

    holder1 = Frame(win1)
    button1 = Button(holder1,text="<<",command=self.first).pack(side=LEFT)
    button2 = Button(holder1,text="<",command=self.previous).pack(side=LEFT)
    button3 = Button(holder1,text="Back",command=self.back).pack(side=LEFT)
    button4 = Button(holder1,text="Stop",command=self.stop).pack(side=LEFT)
    button5 = Button(holder1,text="Play",command=self.play).pack(side=LEFT)
    button6 = Button(holder1,text=">",command=self.next).pack(side=LEFT)
    button7 = Button(holder1,text=">>",command=self.last).pack(side=LEFT)
    holder1.pack(side=TOP)
    
    holder2 = Frame(win1)
    self.slider_frame = Scale(holder2,from_=0,to=self.nframes-1,
                              command=self.frame,orient=HORIZONTAL,
                              label="       Frame")
    self.slider_delay = Scale(holder2,from_=0.0,to=1.0,resolution=0.1,
                              command=self.delay,orient=HORIZONTAL,
                              label="       Delay")
    self.slider_frame.pack(side=LEFT)
    self.slider_delay.pack(side=LEFT)
    holder2.pack(side=TOP)
    
    holder3 = Frame(win1)
    self.label_frame = Label(holder3)
    self.label_frame.pack(side=LEFT)
    holder3.pack(side=TOP)
    
    # image window

    win2 = Toplevel(tkroot)
    self.image_pane = Label(win2,image=self.images[0])
    self.image_pane.pack(side=BOTTOM)
    tkroot.update_idletasks()              # force window to appear

    # display 1st image
    
    self.index = 0
    self.display(self.index)
def viewer(imgdir, kind=Toplevel, numcols=None, height=300, width=300):
    """
    use fixed-size buttons, scrollable canvas;
    sets scrollable (full) size, and places
    thumbs at abs x,y coordinates in canvas;
    caveat: assumes all thumbs are same size
    """
    win = kind()
    win.title('Simple viewer: ' + imgdir)
    quit = Button(win, text='Quit', command=win.quit, bg='beige')
    quit.pack(side=BOTTOM, fill=X)

    canvas = Canvas(win, borderwidth=0)
    vbar = Scrollbar(win)
    hbar = Scrollbar(win, orient='horizontal')

    vbar.pack(side=RIGHT, fill=Y)  # pack canvas after bars
    hbar.pack(side=BOTTOM, fill=X)  # so clipped first
    canvas.pack(side=TOP, fill=BOTH, expand=YES)

    vbar.config(command=canvas.yview)  # call on scroll move
    hbar.config(command=canvas.xview)
    canvas.config(yscrollcommand=vbar.set)  # call on canvas move
    canvas.config(xscrollcommand=hbar.set)
    canvas.config(height=height, width=width)  # init viewable area size
    # changes if user resizes
    thumbs = makeThumbs(imgdir)  # [(imgfile, imgobj)]
    numthumbs = len(thumbs)
    if not numcols:
        numcols = int(math.ceil(math.sqrt(numthumbs)))  # fixed or N x N
    numrows = int(math.ceil(numthumbs / float(numcols)))

    linksize = max(thumbs[0][1].size)  # (width, height)
    fullsize = (
        0,
        0,  # upper left  X,Y
        (linksize * numcols),
        (linksize * numrows))  # lower right X,Y
    canvas.config(scrollregion=fullsize)  # scrollable area size

    rowpos = 0
    savephotos = []
    while thumbs:
        thumbsrow, thumbs = thumbs[:numcols], thumbs[numcols:]
        colpos = 0
        for (imgfile, imgobj) in thumbsrow:
            photo = PhotoImage(imgobj)
            link = Button(canvas, image=photo)
            handler = lambda savefile=imgfile: ViewOne(imgdir, savefile)
            link.config(command=handler, width=linksize, height=linksize)
            link.pack(side=LEFT, expand=YES)
            canvas.create_window(colpos,
                                 rowpos,
                                 anchor=NW,
                                 window=link,
                                 width=linksize,
                                 height=linksize)
            colpos += linksize
            savephotos.append(photo)
        rowpos += linksize
    return win, savephotos