2016-06-08 91 views
2

'''我的代碼打開matplotlib窗口,tkinter但tkinter窗口退出matplotlib窗口後打開。我想他們都在同一時間彈出「」」想要用matplotlib窗口同時打開tkinter窗口嗎?

from pylab import * 
import matplotlib.pyplot as plt 
from matplotlib import style 
import numpy as np 
import pylab 
style.use('seaborn-white') 

x = [0,8,-3,-8] 
y = [0,8,1,-8] 
color=['w','w','w','w'] 

fig = plt.figure() 
ax1 = fig.add_subplot(111) 

scatter(x,y, s=100 ,marker='.', c=color,edgecolor='w') 
plt.ylabel('X') 
plt.xlabel('Y') 
ax1.yaxis.label.set_rotation(0) 
circle1=plt.Circle((0,0),5,color='r',fill=False,linewidth='4') 
fig = plt.gcf() 
fig.gca().add_artist(circle1) 
left,right = ax1.get_xlim() 
low,high = ax1.get_ylim() 
arrow(left, 0, right -left, 0, length_includes_head = True, head_width = 0.15) 
arrow(0, low, 0, high-low, length_includes_head = True, head_width = 0.15) 


fig = pylab.gcf() 
fig.canvas.set_window_title('Inner Slip Ring') 


grid() 
show() 

from tkinter import * 
root=Tk() 
w=Label(root, text="hello") 
w.pack() 
root.mainloop() 

回答

1

只是把一切show()前:

... 
root=Tk() 
w=Label(root, text="hello") 
w.pack() 
#root.mainloop() # Don't use this 

grid() 
show() 
+0

由於它的工作,但你能告訴我爲什麼不要使用root。 mainloop – thedarkgriffen

+0

如果啓動主循環,程序將停止在該行。它會一直等到root被破壞(當你關閉窗口時)。 mainloop只是一個無限循環,用於檢查事件,並且只能在應用程序中調用它(您正在使用show())。 –