2017-05-04 5 views
0

私はTkinterを使い慣れていません。私は多重度計算機のGUIを作成しようとしています。私が多重度を印刷するように言うと、それは一見無作為な文字列を与えます。どんな助け?Tkinterは変数を正しく表示しません

import sys 
import tkinter 
from tkinter import * 

def Start(): 
    numberOneList = [] 
    numberTwoList = [] 
    multiples = 10000 
    iterations = 0 

    multiplicity = int(entry3.get()) 
    numberOne = int(entry1.get()) 
    numberTwo = int(entry2.get()) 

    for i in range(multiples): 
     mNumberOne = numberOne * i 
     numberOneList.append(mNumberOne) 
     mNumberTwo = numberTwo * i 
     numberTwoList.append(mNumberTwo) 
    text1.insert(INSERT, "\n") 
    text1.insert(INSERT, "Common multiplicities:") 
    text1.insert(INSERT, "\n") 
    text1.insert(INSERT, "Calculating...") 
    text1.insert(INSERT, "\n") 
    for i in numberOneList: 
     for a in numberTwoList: 
      if a == i: 
       if a != 0: 
        text1.insert(INSERT, int(entry1.get()), "x", i/int(entry1.get()), "=", i) 
        text1.insert(INSERT, int(entry2.get()), "x", a/int(entry2.get()), "=", a) 
        text1.insert(INSERT, "\n") 
        iterations += 1 
        if iterations == multiplicity: 
         sys.exit() 
        else: 
         continue 
       else: 
        continue 
      else: 
       continue 

master = tkinter.Tk() 
master.title("Multiplicity Calculator") 

text1 = Text(master) 
text1.pack(side = BOTTOM) 

label1 = Label(master, text = "Number 1: ") 
label1.pack(side = LEFT) 

entry1 = Entry(master, bd = 5, textvariable = IntVar()) 
entry1.pack(side = LEFT) 

label2 = Label(master, text = "Number 2: ") 
label2.pack(side = LEFT) 

entry2 = Entry(master, bd = 5, textvariable = IntVar()) 
entry2.pack(side = LEFT) 

label3 = Label(master, text = "Number of Multiplicities") 
label3.pack(side = LEFT) 

entry3 = Entry(master, bd = 5, textvariable = IntVar()) 
entry3.pack(side = LEFT) 

button1 = Button(master, text = "Calculate", width = 8, command = Start) 
button1.pack() 



master.mainloop() 

問題は、任意のヘルプライン

text1.insert(INSERT, int(entry1.get()), "x", i/int(entry1.get()), "=", i) 
text1.insert(INSERT, int(entry2.get()), "x", a/int(entry2.get()), "=", a) 

感謝です!

答えて

0

コンマを使用する代わりに、すべてを1つの引数に連結します。あなたが新たに挿入されたテキスト

text.insert(INSERT, "link", ("a", "href"+href)) 
に 1つまたは複数のタグを付けるために、インサートメソッドにオプションの第三引数を使用することができます

text1.insert(INSERT, str(int(entry1.get())) + "x" + str(i/int(entry1.get())) + "=" + str(i)) 

関連する問題