質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

739閲覧

tkinterでEntry Box内でenter押されたらEntry Boxのテキスト取得

退会済みユーザー

退会済みユーザー

総合スコア0

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2018/10/19 10:38

###したい事
tkinterでEntry Boxに入力された文字をAmazonから値段とかをwebスクレイピングしようとしてます

###エラーが起きたところ
pythonのtkinterでEntry Box内でEnterが押されたらEntry Box内のテキストを取得
しようとしたら以下のようなエラーが発生しました

###エラー内容
line 40, in Bind_command1
if self.sh_box1.get() == '':
AttributeError: 'Event' object has no attribute 'sh_box1'

python3

1import tkinter as tk 2import tkinter.filedialog as tkf 3import os 4import requests 5from apscheduler.schedulers.blocking import BlockingScheduler 6from bs4 import BeautifulSoup 7 8 9class Form_config: 10 def __init__(self): 11 self.root = tk.Tk() 12 self.root.title("main") 13 self.root.attributes("-fullscreen", True) 14 self.state = False 15 self.root.option_add("*font", ["MS Pゴシック"], 22) 16 17 self.Label_text1 = tk.Label(text="saerch name") 18 self.Label_text1.place(x=500, y=5) 19 20 self.sh_box1 = tk.Entry(width=40, bd=4) 21 self.sh_box1.place(x=630, y=5) 22 self.sh_box1.bind("<Return>", Form_config.Bind_command1) 23 24 self.input_butoon1 = tk.Button(text="Add", command=self.Button_command1) 25 self.input_butoon1.place(x=1010, y=3) 26 self.input_butoon2 = tk.Button(text="start", command=self.Button_command2) 27 self.input_butoon2.place(x=1110, y=3) 28 29 self.text_widget = tk.Text(self.root) 30 self.text_widget.place(x=500, y=50) 31 32 self.root.bind("<Escape>", self.end_fullscreen) 33 self.Menuber_config() 34 self.root.config(menu=self.menubar) 35 self.root.mainloop() 36 37 def Bind_command1(self): 38 if self.sh_box1.get() == '': 39 return False 40 elif self.sh_box1.get() != '': 41 self.requests_url = requests.get( 42 'https://www.amazon.co.jp/s/ref=nb_sb_ss_i_8_4?__mk_ja_JP=カタカナ&field-keywords={}'.format( 43 self.sh_box1.get())) 44 for self.count in range(0, 7): 45 if self.requests_url.status_code == requests.codes.ok: 46 self.soup = BeautifulSoup(self.requests_url.content, 'html.parser') 47 self.the_text = self.soup.select_one( 48 '#result_1 > div > div:nth-child(3) > div:nth-child(1) > a > h2').get_text(strip=True) 49 self.price = self.soup.select_one( 50 '#result_0 > div > div > div > div.a-fixed-left-grid-col.a-col-right > div:nth-child(2) > div.a-column.a-span7 > div:nth-child(2) > a > span.a-size-base.a-color-price.s-price.a-text-bold').get_text( 51 strip=True) 52 tk.Checkbutton(text=self.the_text).pack(tk.E) 53 self.sh_box1.delete() 54 return True 55 56 def Button_command1(self): 57 pass 58 59 def Button_command2(self): 60 pass 61 62 def File_open(self): 63 self.fTyp = [("", ".csv")] 64 self.iDir = os.path.abspath(os.path.dirname(__file__)) 65 self.file = tkf.askopenfilename(filetypes=self.fTyp, initialdir=self.iDir) 66 67 def Menuber_config(self): 68 self.menubar = tk.Menu(self.root) 69 self.filemenu = tk.Menu(self.menubar, tearoff=0) 70 self.filemenu.add_command(label="Import", command=self.File_open) 71 self.filemenu.add_command(label="Export", command=self.File_open) 72 self.filemenu.add_command(label="Close", command=self.File_open) 73 self.filemenu.add_separator() 74 self.menubar.add_cascade(label="Config", menu=self.filemenu) 75 76 def Status_config(self, txt): 77 self.status = tk.Label(self.root, text=txt, borderwidth=2, relief="groove") 78 self.status.pack(side=tk.BOTTOM, fill=tk.X) 79 80 def end_fullscreen(self, event=None): 81 self.state = False 82 self.root.attributes("-fullscreen", False) 83 84 self.root.minsize(1400, 800) 85 86 return "break" 87 88 89Form_config()
### 試したこと すいません なにをすればいいか分からなくて 試せていません ### 補足情報(FW/ツールのバージョンなど) python3.6 windows10 pycharm コードは書き途中です

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Amazon APIを使ったらできました
すいません

投稿2018/10/20 10:46

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問