Canvas.pack() -> "Python a cessé de fonctionner"
Salut,
J'ai décidé de passer enfin à Python 3. Je mets à jour un programme avec interface tkinter. J'ai de la chance il n'y a presque rien a changer. Cependant j'ai un soucis avec un canvas matplotlib. Lorsque j'exécute le programme j'ai droit à un bon vieux plantage:
Citation:
Python a cessé de fonctionner
J'ai eu un peu de mal a repérer la ligne qui pêche (pas terrible ce jeux de mots) car aucun traceback n'est renvoyé.
Voici un bout de code permettant de reproduire le problème:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Gui modules
import tkinter as tk
import tkinter.ttk
import tkinter.messagebox
# Plotting modules
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
class MainApplication(tk.Frame):
"""Main frame of the user interface. Parent is root."""
def __init__(self, master, *args, **kwargs):
tk.Frame.__init__(self, master, *args, **kwargs)
self.master = master
self.initialize()
def initialize(self):
# Frame to hold content
frame = tk.Frame(self, name='polar')
frame.pack(fill=tk.BOTH, expand=tk.Y, padx=2, pady=3)
# Set up a figure in a canvas
self.figure = plt.figure(1)
self.canvas = FigureCanvasTkAgg(self.figure, master=frame)
self.canvas.get_tk_widget().config(height=40, width=200)
self.canvas.get_tk_widget().pack(fill='both', expand=1, padx=2, pady=2)
#self.canvas.draw()
def stop_gui():
"""Function called to cleanly stop the interface"""
if tkinter.messagebox.askokcancel('Quit', 'Do you want to quit?'):
root.quit()
root.destroy()
if __name__ == '__main__':
root = tk.Tk()
root.resizable(0,0)
root.configure(background='black')
root.title('App')
MainApplication(root).pack()
root.protocol("WM_DELETE_WINDOW", stop_gui)
root.mainloop() |
Le problème intervient à la ligne:
Code:
self.canvas.get_tk_widget().pack(fill='both', expand=1, padx=2, pady=2)
Si commentée, tout ce passe bien. Je précise aussi qu'auparavant (python 2.7) ça fonctionnait nickel. Ah oui, et j'utilise tk 8.5.18 et matplotlib 1.5.1 dans les deux cas. J'ai essayé avec .grid() au lieu de pack(), même soucis.
Rien trouvé sur google. Une idée?
J