Code: Alles auswählen
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 03 13:18:50 2016
@author: rk480158
"""
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
import sys
import matplotlib as mpl
from matplotlib.backends.backend_agg import FigureCanvasAgg
from PyQt4 import QtGui, QtCore
import matplotlib.pyplot as plt
from matplotlib import rcParams
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 mathTex_to_QPixmap(mathTex, fs):
#---- set up a mpl figure instance ----
fig = mpl.figure.Figure()
fig.patch.set_facecolor('none')
fig.set_canvas(FigureCanvasAgg(fig))
renderer = fig.canvas.get_renderer()
#---- plot the mathTex expression ----
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')
ax.patch.set_facecolor('none')
t = ax.text(0, 0, mathTex, ha='left', va='bottom', fontsize=fs)
#---- fit figure size to text artist ----
fwidth, fheight = fig.get_size_inches()
fig_bbox = fig.get_window_extent(renderer)
text_bbox = t.get_window_extent(renderer)
tight_fwidth = text_bbox.width * fwidth / fig_bbox.width
tight_fheight = text_bbox.height * fheight / fig_bbox.height
fig.set_size_inches(tight_fwidth, tight_fheight)
#---- convert mpl figure to QPixmap ----
buf, size = fig.canvas.print_to_buffer()
qimage = QtGui.QImage.rgbSwapped(QtGui.QImage(buf, size[0], size[1],
QtGui.QImage.Format_ARGB32))
qpixmap = QtGui.QPixmap(qimage)
return qpixmap
def ausgang():
headerLabels = '$C_{soil}=(1 - n) C_m + \\theta_w C_w$'
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()
c = Label(root, text=mathTex_to_QPixmap(headerLabels, 10))
c.pack()
# 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()