Tkinter单元格位置(x,y)?

时间:2015-03-31 12:37:49

标签: python-2.7 python-3.x tkinter

有没有办法获得单元格大小和单元格角落的x,y位置?我的框架左侧有单选按钮,我想根据大小的大小调整图像大小框架。

我最终要做的是创建一个占据大量单元格的块,这样我可以放大我的.tif并向左/向右滚动和向上/向下滚动。这种小部件是否已经存在?

这是非常我现在所拥有的概要

from tkinter import *
from PIL import Image,ImageTk
import os

file_path = "C:/Users/..."
dirs = os.listdir(file_path)


root = Tk()
# Set window size slightly below screen size
width = int(root.winfo_screenwidth() - root.winfo_screenwidth()/9)
height = int(root.winfo_screenheight() - root.winfo_screenheight()/9)
root.geometry(str(width)+"x"+str(height))



class Application(Frame):
    def __init__(self,master):
        Frame.__init__(self,master)
        os.chdir(file_path)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        Label(self,
            text = "Available Files"
            ).grid(row=0,column=0,sticky=W)
        Label(self,
            text = "Select one:"
            ).grid(row=1,column=0,sticky=W)

        self.filelist = StringVar()
        self.filelist.set(0)
        # Radio buttons of files in directory
        i = 1
        for files in dirs:
            if os.path.isfile(os.path.join(file_path, files)):
                i += 1
                Radiobutton(self,
                            text=files,
                            variable=self.filelist,
                            value=files,
                            command=self.update_text
                            ).grid(row=i,column=0,sticky=W)
        # Message box
        self.result = Text(self, width=40, height=5, wrap=WORD)
        self.result.grid(row=i, column=0, columnspan=3)

    def update_text(self):
        message = "File selected is "
        message += self.filelist.get()
        self.display_image()
        self.result.delete(0.0, END)
        self.result.insert(0.0, message)

    def display_image(self):
        try:
            self.image = Image.open(self.filelist.get())
        except:
            message += self.filelist.get() + " doesn't exist. This is awkward..."

        img_width,img_height = self.image.size
        self.preview_image = ImageTk.PhotoImage(self.image)
        self.preview = Label(self, image=self.preview_image)
        self.preview.grid(row=0, column=3, rowspan=20)

    app = Application(root)
    root.mainloop()

0 个答案:

没有答案