1

My problem is how to use the file I will select with askopenfilename() later on, for example to put it the canvas ? What should I put instead of the "?" at "Im = ?" ? Thank you ! Sorry I am very much a beginner

import tkinter as tk
from tkinter import *
from tkinter.filedialog import *



root=tk.Tk()
root.geometry('1000x690')
root.title("Baccalauréat ISN 2017")

# # #
def Open_Image():
askopenfilename()

# # #
B13= Button(root, text='Open Image', height=5, width= 25, command = askopenfilename)
B13.grid(row=1, column=5, sticky= W + E)

Im = ?
# # #




Nim = Im.resize((int((Im.width*514)/Im.height), 514))   #maxsize =(821, 514) ---> size of the canvas 821-length; 514 -height


nshow = ImageTk.PhotoImage(Nim)

Can = tk.Canvas(root, background = 'blue') 

Can.grid(row = 1, column = 0, rowspan = 6, columnspan = 5, sticky = W + E + N + S)
Cim = Can.create_image(0, 0,  anchor = NW, image = nshow) # "0, 0" space between the picture and the borders

# # #

mainloop()
Jos Maesen
  • 21
  • 1

1 Answers1

0

Use this code to store a file as a variable:

    path = tkFileDialog.askdirectory()
    os.chdir(path)
    f = open(file_name, mode)

mode can be:

'r' - if you want to read data from the file.

'w' - if you want to write data to the file.

You can read the data of the file using the command: file.read(). And write data using the command: file.write(data)(The mode should be accordingly).

Read further in here.

Hopefully this will help you,Yahli.

Mr Yahli
  • 321
  • 2
  • 13
  • Thank you so much for answering but I do not really get it: where should I fit this inside out of my code ? I'm really a beginner so.. :) – Jos Maesen May 06 '17 at 18:56