parent
2b0bebfdc0
commit
dc8788f5da
@ -0,0 +1,54 @@
|
|||||||
|
from Tkinter import *
|
||||||
|
|
||||||
|
def askopenfilename():
|
||||||
|
""" Prints the selected files name """
|
||||||
|
# get filename, this is the bit that opens up the dialog box this will
|
||||||
|
# return a string of the file name you have clicked on.
|
||||||
|
filename = tkFileDialog.askopenfilename()
|
||||||
|
if filename:
|
||||||
|
# Will print the file name to the text box
|
||||||
|
print filename
|
||||||
|
|
||||||
|
# a subclass of Canvas for dealing with resizing of windows
|
||||||
|
class ResizingCanvas(Canvas):
|
||||||
|
def __init__(self,parent,**kwargs):
|
||||||
|
Canvas.__init__(self,parent,**kwargs)
|
||||||
|
self.bind("<Configure>", self.on_resize)
|
||||||
|
self.height = self.winfo_reqheight()
|
||||||
|
self.width = self.winfo_reqwidth()
|
||||||
|
|
||||||
|
def on_resize(self,event):
|
||||||
|
# determine the ratio of old width/height to new width/height
|
||||||
|
wscale = float(event.width)/self.width
|
||||||
|
hscale = float(event.height)/self.height
|
||||||
|
self.width = event.width
|
||||||
|
self.height = event.height
|
||||||
|
# resize the canvas
|
||||||
|
self.config(width=self.width, height=self.height)
|
||||||
|
# rescale all the objects tagged with the "all" tag
|
||||||
|
self.scale("all",0,0,wscale,hscale)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
root = Tk()
|
||||||
|
myframe = Frame(root)
|
||||||
|
myframe.pack(fill=BOTH, expand=YES)
|
||||||
|
|
||||||
|
mycanvas = ResizingCanvas(myframe,width=850, height=400, bg="red", highlightthickness=0)
|
||||||
|
mycanvas.pack(fill=BOTH, expand=YES)
|
||||||
|
|
||||||
|
button = Button(root, text='GetFileName', command=askopenfilename)
|
||||||
|
# this puts the button at the top in the middle
|
||||||
|
button.grid(row=1, column=1)
|
||||||
|
|
||||||
|
# add some widgets to the canvas
|
||||||
|
#mycanvas.create_line(0, 0, 200, 100)
|
||||||
|
#mycanvas.create_line(0, 100, 200, 0, fill="red", dash=(4, 4))
|
||||||
|
#mycanvas.create_rectangle(50, 25, 150, 75, fill="blue")
|
||||||
|
|
||||||
|
# tag all of the drawn widgets
|
||||||
|
#mycanvas.addtag_all("all")
|
||||||
|
|
||||||
|
root.mainloop()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in new issue