第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Tkinter gui 僅在調(diào)整窗口大小時(shí)繪制圖形

Tkinter gui 僅在調(diào)整窗口大小時(shí)繪制圖形

素胚勾勒不出你 2023-09-05 15:26:42
我有一個(gè)腳本,將一個(gè)簡單的情節(jié)嵌入到 Tkinter gui 中。有一個(gè)用于繪圖的按鈕,當(dāng)按下它時(shí),它似乎什么也沒做,但如果窗口稍微調(diào)整大小,繪圖就會(huì)彈出。gui 窗口足夠大以包含情節(jié),我在這里做錯(cuò)了什么?代碼print('\n'*3)import tkinter as tkimport matplotlib.pyplot as plt  from matplotlib.backends.backend_tkagg import FigureCanvasTkAggfrom matplotlib.figure import Figure#MAKE ROOT WINDOWroot = tk.Tk()root.title("Tab Widget")#root.geometry("600x450")#MAKE A FIGURE OBJECTmy_figure = Figure(figsize = (4, 4), dpi = 100) #MAKE A FRAME WIDGETframe1 = tk.Frame(root, bd=2, relief=tk.GROOVE)frame1.pack(side=tk.LEFT, anchor=tk.N, fill=tk.BOTH, expand=True)frame2 = tk.Frame(root, bd=2, relief=tk.GROOVE)frame2.pack(side=tk.RIGHT)#MAKE A CANVAS OBJECTmy_canvas = FigureCanvasTkAgg(my_figure, master = frame1) # creating the Tkinter canvas containing the Matplotlib figure  # TURN THE CANVAS OBJECT INTO A CANVAS WIDGETmy_canvas.get_tk_widget().pack() # placing the canvas on the Tkinter windowmy_canvas.draw()def plotData():    plot1 = my_figure.add_subplot(111) # adding the subplot     x = [1,2,3,4,5]    y = [11, 3, 6, 9,12]    plot1.plot(x, y, marker='o', c='b')# MAKE BUTTON TO PLOT GRAPHbutton1 = tk.Button(frame2, text = "Plot", command = plotData, relief = tk.GROOVE, padx =20, pady =20 )button1.pack(side="right")root.mainloop()期望的結(jié)果無需調(diào)整大小即可查看繪圖的 GUI 窗口。
查看完整描述

1 回答

?
慕森卡

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個(gè)贊

您需要my_canvas.draw()在以下時(shí)間結(jié)束時(shí)致電plotData():


def plotData():

    plot1 = my_figure.add_subplot(111) # adding the subplot 

    x = [1,2,3,4,5]

    y = [11, 3, 6, 9,12]

    plot1.plot(x, y, marker='o', c='b')

    my_canvas.draw() # draw the graph


查看完整回答
反對(duì) 回復(fù) 2023-09-05
  • 1 回答
  • 0 關(guān)注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)