Seite 1 von 1

ipython notebook tkinter code zum laufen bringen

Verfasst: Mittwoch 9. März 2016, 15:05
von Brando
Hallo,
folgendes Programm will ich auf jupyter notebook zum laufen bringe:

Code: Alles auswählen

from Tkinter import *
import numpy as np
from random import randint
from sympy.matrices import *
from sympy.printing import *
from IPython.display import display, HTML, Math, Latex, clear_output
# from ipywidgets import widgets
# from random import randint


v=""
g=0
dot = 0
#def sende1():                
# # s = Eingabefeld1.get()
#    global s
#    v=Eingabefeld1.get()
#    print "v in sende ist jetzt",v
#    g=int(v)
#    if g>0:
#        if  g == dot:
#            print dot
#            z = Label(root, text="Richtig")
#            z.pack()
#        else: 
#            z = Label(root, text="Falsch")
#            z.pack()

  
# root = Tk()
# Label(root, text="Ergebnis").grid(row=0)
# Label(root, text="Ergebnis").grid(row=1)
# e1 = Entry(root)
# e2 = Entry(root)
# e1.grid(row=0, column=1)
# e2.grid(row=1, column=1) 
# master = Tk()

def ausgang():
    def sende1():                
 # s = Eingabefeld1.get()
        global s
        v=Eingabefeld1.get()
        print "v in sende ist jetzt",v
        g=int(v)
        if g:
            if  g == dot:
                print dot
                z = Label(root, text="Richtig")
                z.pack()
            else: 
                z = Label(root, text="Falsch")
                z.pack()     
    
    root=Tk()
    s = StringVar()
# v = StringVar()
    Eingabefeld1= Entry(root,bg='white', textvariable=s)
    Eingabefeld1.pack()
# w = Label(root, text="Hello Tkinter!")
# w.pack()
    x1 = randint(-10,10)
    x2 = randint(-10,10)
    x3 = randint(-10,10)
    x= np.array([x1,x2,x3])
##x_shape = np.array([0,0,0])
##for i in xrange(len(x)):
##    x_shape[i]=x[i]
##
##x_shape.shape = (3,1)
    a = Label(root, text=x)
    a.pack()
    y1 = randint(-10,10)
    y2 = randint(-10,10)
    y3 = randint(-10,10)
    y = np.array([y1,y2,y3])

#    x = Matrix([randint(-20,20), randint(-20,20), randint(-20,20)])
#    y = Matrix([randint(-20,20), randint(-20,20), randint(-20,20)])
    a1 = latex(x)
    
#    a2 = latex(y)
#    print "a1 ist jetzt", a1
    a1 = a1.replace("left[", "left(")
#    a2 = a2.replace("left[", "left(")
    a1 = a1.replace("right]", "right)")
#    a2 = a2.replace("right]", "right)")
#    str1 = "$\langle" + a1 + ", " + a2 + "\\rangle$"

    # y_transpose = np.transpose(y)
    print a1
    b = Label(root, text=y)
    b.pack() 
    dot = np.dot(x,y)
    #dot = x.dot(y)
    #print dot
    Knopf1 = Button(root,text='Sende Ergebnis',command=sende1)
    Knopf1.pack(side=LEFT)
    Knopf2 = Button(root,text='Neue Berechnung',command=ausgang)
    Knopf2.pack(side=RIGHT)
    root.mainloop()
# print s
# v=s.get()
# print "v ist jetzt:",v
# s=Eingabefeld1.get()
# z = Label(root, text=dot)
# z.pack()
# try:
#    v
# except NameError:
#    v = "None"

# print "v ist jetzt nach None:",v

# if v!="":
#    g = int(v)
#    print "v jetzt im Vergleich ist", v
# print "g ist:",g
#if g>0:
#    if  g == dot:
#        print dot
#        z = Label(root, text="Richtig")
#        z.pack()
#    else: 
#        z = Label(root, text="Falsch")
#        z.pack()

# root = Tk()

ausgang()

# root.mainloop()
# mainloop()
Dazu habe ich auf meinem geheimen .ipython Ordner dieses Programm als tkiner_probe.py abgespeichert. Eigentlich sollte man dann nur in notebook ausgang() eingeben und das Programm läuft. Tut es aber nicht. Was muss ich noch bedenken?