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

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

新規登録して質問してみよう
ただいま回答率
85.48%
import

自身のプラットフォーム・プログラム・データセットに対して、外部ソースを取り込むプロセスをimportと呼びます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

1134閲覧

【Python】Entryから取得した値をint型として計算したい。

JinGoda

総合スコア20

import

自身のプラットフォーム・プログラム・データセットに対して、外部ソースを取り込むプロセスをimportと呼びます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/02/13 20:50

前提・実現したいこと

下記コードのうちdamagecalculation.pyのH =..., A = ..., ...の計算式がうまくいくようにしたいと思っています。エラーとしてint型とEntry型が混在していることはわかっているのですが、Entry型をint型として計算可能にする方法がわからず困っています。

発生している問題・エラーメッセージ

Traceback (most recent call last): File "damagecalculation.py", line 17, in <module> H = int(int(pokemon.dp.H * 2 + pokemon.dp.iv + pokemon.dp.ev / 4) * pokemon.dp.lv / 100 + pokemon.dp.lv + 10) TypeError: unsupported operand type(s) for +: 'int' and 'Entry' PS C:\Users\gojin\desktop\sqlite3> python damagecalculation.py Traceback (most recent call last): File "damagecalculation.py", line 17, in <module> H = int(int(pokemon.dp.H * 2 + pokemon.dp.iv + pokemon.dp.ev / 4) * pokemon.dp.lv / 100 + pokemon.dp.lv + 10) TypeError: unsupported operand type(s) for +: 'int' and 'Entry'

該当のソースコード

Python

1#damagecalculation.py 2 3# H = ...の位置でエラーが発生しました。 4H = int(int(pokemon.dp.H * 2 + pokemon.dp.iv + pokemon.dp.ev / 4) * pokemon.dp.lv / 100 + pokemon.dp.lv + 10) 5A = int(int(int(pokemon.ap.A * 2 + pokemon.ap.iv + pokemon.ap.ev / 4) * pokemon.ap.lv / 100 + 5) * nature.na()) 6B = int(int(int(pokemon.dp.B * 2 + pokemon.dp.iv + pokemon.dp.ev / 4) * pokemon.dp.lv / 100 + 5) * nature.nb()) 7C = int(int(int(pokemon.ap.C * 2 + pokemon.ap.iv + pokemon.ap.ev / 4) * pokemon.ap.lv / 100 + 5) * nature.nc()) 8D = int(int(int(pokemon.dp.D * 2 + pokemon.ap.iv + pokemon.ap.ev / 4) * pokemon.ap.lv / 100 + 5) * nature.nd()) 9AS = int(int(int(pokemon.ap.S * 2 + pokemon.ap.iv + pokemon.ap.ev / 4) * pokemon.ap.lv / 100 + 5) * nature.ans()) 10DS = int(int(int(pokemon.dp.S * 2 + pokemon.ap.iv + pokemon.ap.ev / 4) * pokemon.ap.lv / 100 + 5) * nature.dns())

Python

1#pokemon.py 2 3import tkinter as tk 4import tkinter.ttk as ttk 5import sqlite3 as sql 6 7import main 8import cursor 9 10class AttackingPokemon: 11 12 def __init__(self, name, type1, type2, lv, iv, ev, nature, status, A, C, S): 13 14 self.name = name 15 self.type1 = type1 16 self.type2 = type2 17 self.lv = lv 18 self.iv = iv 19 self.ev = ev 20 self.nature = nature 21 self.status = status 22 self.A = A 23 self.C = C 24 self.S = S 25 26class DefendingPokemon: 27 28 def __init__(self, name, type1, type2, lv, iv, ev, nature, status, H, B, D, S): 29 30 self.name = name 31 self.type1 = type1 32 self.type2 = type2 33 self.lv = lv 34 self.iv = iv 35 self.ev = ev 36 self.nature = nature 37 self.status = status 38 self.H = H 39 self.B = B 40 self.D = D 41 self.S = S 42 43ap = AttackingPokemon(main.aname, cursor.at1[0], cursor.at2[0], main.alventry, main.aiventry, main.aeventry, main.anaturecheck, '-', cursor.A[0], cursor.C[0], cursor.aS[0]) 44dp = DefendingPokemon(main.dname, cursor.dt1[0], cursor.dt2[0], main.dlventry, main.diventry, main.deventry, main.dnaturecheck, '-', cursor.H[0], cursor.B[0], cursor.D[0], cursor.dS[0])

Python

1#main.py 2 3win = tk.Tk() 4win.title('ダメージ計算') 5win.geometry('600x700') 6 7atkframe = tk.Frame(win) 8atkframe.pack(pady = 5) 9 10nameframe = tk.Frame(atkframe) 11nameframe.pack(pady = 5) 12alabel = tk.Label(nameframe, text = "攻撃側 ") 13alabel.pack(side = 'left') 14aname = tk.Entry(nameframe, name = 'aname') 15aname.pack(side = 'left') 16aname.insert(index = 'insert', string = "インテレオン") 17 18lvframe = tk.Frame(atkframe) 19lvframe.pack(pady = 5) 20alvlabel = tk.Label(lvframe, text = "レベル ") 21alvlabel.pack(side = 'left') 22alventry = tk.Entry(lvframe) 23alventry.pack(side = 'left') 24alventry.insert(index = 'insert', string = '50') 25 26idframe = tk.Frame(atkframe) 27idframe.pack(pady = 5) 28aivlabel = tk.Label(idframe, text = "個体値 ") 29aivlabel.pack(side = 'left', ipadx = 5) 30aiventry = tk.Entry(idframe) 31aiventry.pack(side = 'left') 32aiventry.insert(index = 'insert', string = '31') 33 34aevlabel = tk.Label(idframe, text = "努力値 ") 35aevlabel.pack(side = 'left') 36aeventry = tk.Entry(idframe) 37aeventry.pack(side = 'left', ipadx = 5) 38aeventry.insert(index = 'insert', string = '252') 39 40natureframe = tk.Frame(atkframe) 41natureframe.pack(pady = 8) 42anaturelabel = tk.Label(natureframe, text = "性格 ") 43anaturelabel.pack(side = 'left') 44anaturecheck = ttk.Combobox(natureframe, state = 'readonly') 45anaturecheck['values'] = ("", "さみしがり", "いじっぱり", "やんちゃ", "ゆうかん", "ずぶとい", "わんぱく", "のうてんき", "のんき", "ひかえめ", "おっとり", "うっかりや", "れいせい", "おだやか", "おとなしい", "しんちょう", "なまいき", "おくびょう", "せっかち", "ようき", "むじゃき", "てれや", "がんばりや", "すなお", "きまぐれ", "まじめ") 46anaturecheck.current(0) 47anaturecheck.pack(side = 'left') 48 49moveframe = tk.Frame(atkframe) 50moveframe.pack() 51mlabel = tk.Label(moveframe, text = "わざ名 ") 52mlabel.pack() 53mname = tk.Entry(moveframe) 54mname.pack() 55mname.insert(index = 'insert', string = "アクアジェット")

Python

1#cursor.py 2 3import tkinter as tk 4import sqlite3 as sql 5import tkinter.ttk as ttk 6 7import main 8 9dbpath = "dex.sqlite3" 10conn = sql.connect(dbpath) 11cur = conn.cursor() 12 13cur.execute("SELECT type1 FROM dex WHERE name = '%s'" % main.aname.get()) 14at1 = cur.fetchone() 15cur.execute("SELECT type2 FROM dex WHERE name = '%s'" % main.aname.get()) 16at2 = cur.fetchone() 17cur.execute("SELECT A FROM dex WHERE name = '%s'" % main.aname.get()) 18A = cur.fetchone() 19cur.execute("SELECT C FROM dex WHERE name = '%s'" % main.aname.get()) 20C = cur.fetchone() 21cur.execute("SELECT S FROM dex WHERE name = '%s'" % main.aname.get()) 22aS = cur.fetchone() 23 24cur.execute("SELECT type1 FROM dex WHERE name = '%s'" % main.dname.get()) 25dt1 = cur.fetchone() 26cur.execute("SELECT type2 FROM dex WHERE name = '%s'" % main.aname.get()) 27dt2 = cur.fetchone() 28cur.execute("SELECT H FROM dex WHERE name = '%s'" % main.dname.get()) 29H = cur.fetchone() 30cur.execute("SELECT B FROM dex WHERE name = '%s'" % main.dname.get()) 31B = cur.fetchone() 32cur.execute("SELECT D FROM dex WHERE name = '%s'" % main.dname.get()) 33D = cur.fetchone() 34cur.execute("SELECT S FROM dex WHERE name = '%s'" % main.dname.get()) 35dS = cur.fetchone() 36 37cur.execute("SELECT mtype FROM moves WHERE name = '%s'" % main.mname.get()) 38mmtype = cur.fetchone() 39cur.execute("SELECT power FROM moves WHERE name = '%s'" % main.mname.get()) 40mpower = cur.fetchone() 41 42cur.execute("SELECT type FROM moves WHERE name = '%s'" % main.mname.get()) 43mtype = cur.fetchone() 44cur.execute("SELECT rev FROM types WHERE type1 = '%s' AND type2 = '%s'" % (mtype[0], dt1[0])) 45rev1 = cur.fetchone() 46cur.execute("SELECT rev FROM types WHERE type1 = '%s' AND type2 = '%s'"% (mtype[0], dt2[0])) 47rev2 = cur.fetchone()

試したこと

int(pokemon.dp.iv.get())とするなどして返還を試みました。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

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

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

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

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

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

guest

回答1

0

ベストアンサー

TypeError: unsupported operand type(s) for +: 'int' and 'Entry'

訳: int + Entry はサポートしておりません。

Entryが代入されてる変数を探して .get() でEntry内容を取り出しましょう。

投稿2020/02/13 23:05

shiracamus

総合スコア5406

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

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

JinGoda

2020/02/14 03:42

.get()を入れる部分を間違えて試していたようです... .get()を適切な部分に入れることで解決しました!ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問