前提・実現したいこと
pythonのTkinterを使ってUIのシステムを作っているのですが、キーワードの横にあるテキストボックスtxtに文字を入力し、ボタンを押すと、グラフが表示され、下にあるテキストボックスco_wordにメッセージを表示させたいです。
発生している問題・エラーメッセージ
UIの画面は表示されるのですが、文字を入力してボタンを押しても何も変化が現れません。
該当のソースコード
python
1import os 2import sys 3import string 4from collections import OrderedDict 5import io 6import tkinter as tk 7import numpy as np 8import matplotlib 9import matplotlib.pyplot as plt 10from matplotlib.figure import Figure 11from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 12 13def word_search(): 14 root = tk.Tk() 15 root.title("search") 16 root.geometry("600x600") 17 18 19 title = tk.Entry(width=20) 20 title.place(x=100, y=70) 21 22 23 lbl = tk.Label(text='キーワード') 24 lbl.place(x=30, y=140) 25 26 txt = tk.Entry(width=20) 27 txt.place(x=100, y=140) 28 29 30 co_word=tk.Text(width=30) 31 co_word.place(x=30, y=250) 32 33 34 button = tk.Button(root, text="search", command="pushed") 35 button.place(x=100, y=200) 36 root.mainloop() 37 38 def pushed(): 39 left=np.array([1,2,3,4]) 40 height=np.array([50,66,77,88]) 41 plt.plot(left,height) 42 plt.xlabel('week') 43 plt.ylabel('count') 44 plt.show() 45 46 twext=txt.get() 47 if text==[]: 48 raise Exception('Error!') 49 message-"グラフが表示されました" 50 co_word.insert(tk.END,message) 51 52 53word_search()
試したこと
一度UIを閉じて再度表示させればうまくいくとネットで見たので(URLは覚えておりません)
最後の行に
root.destroy()
root.mainloop()
を入れ、実行しても何も変化しませんでした。
補足情報(FW/ツールのバージョンなど)
動作環境はubuntu18.04です
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/16 03:38