Tkinter entry widget
Verfasst: Dienstag 22. März 2022, 15:01
Hallo everyone. :)
I am new here in the python forum and I try to write a program which I can do some calculations with.
programm run but i cant make the button alive like if its clicked, the entry widget will be inactive and when i click back again the entry widget get back to active mode.
and the plt.show() window is opened out of tkinter window. i need it in tkinter window and everytime i change the values the i must receive the updated window
thankyou so much for your response
the code is
from tkinter import *
from PIL import ImageTk, Image
import scipy as sc
import scipy.special as scs
import scipy.optimize as sco
import matplotlib.pyplot as plt
import numpy as np
root = Tk()
root.title("Coax TE Mode")
root.geometry("1400x1000")
root.config(background="#145")
var = IntVar()
# generate the window
title = Label(root, text="Coax TE Mode", font=('Helvetica', 22), bg="#145", fg="white")
title.grid(row=0, column=3, padx=20, pady=20)
leer = Label(root, text="", bg="#145", fg="#145") #abstand zwischen title und andere funktionen
leer.grid(row=1, column=1)
leer = Label(root, text="", bg="#145", fg="#145")
leer.grid(row=2, column=1)
# Impedanz = zl (in die gleichung als (z) gezeichnet)
impedanz_Label = Label(root, text="Impedanz", font=12, bg="#145", fg="white")
impedanz_Label.grid(row=6, column=0, padx=10, pady=10)
impedanz_Var = IntVar()
impedanz_Entry = Entry(root, textvariable=impedanz_Var, width=32, borderwidth=5, )
impedanz_Entry.grid(row=6, column=1, columnspan=4, padx=10, pady=10)
# Innenleiter = in_d (in die gleichung als (in_d) gezeigt)
innenleiter_Label = Label(root, text="Innenleiter", font=12, bg="#145", fg="white")
innenleiter_Label.grid(row=4, column=0, padx=10, pady=10)
innenleiter_Var = IntVar()
innenleiter_Entry = Entry(root, textvariable=innenleiter_Var, width=32, borderwidth=5)
innenleiter_Entry.grid(row=4, column=1, columnspan=4, padx=10, pady=10)
# Aussenleiter = aus_d (in die gleichung als (aus_d) gezeigt)
aussenleiter_Label = Label(root, text="Außenleiter", font=12, bg="#145", fg="white")
aussenleiter_Label.grid(row=5, column=0, padx=10, pady=10)
aussenleiter_Var = IntVar()
aussenleiter_Entry = Entry(root, textvariable=aussenleiter_Var, width=32, borderwidth=5)
aussenleiter_Entry.grid(row=5, column=1, columnspan=4, padx=10, pady=10)
# eps_r = in die gleichung als (eps_r) gezeigt
eps_r_Label = Label(root, text="eps_r", font=12, bg="#145", fg="white")
eps_r_Label.grid(row=7, column=0, padx=10, pady=10)
eps_r_Var = IntVar()
eps_r_Entry = Entry(root, textvariable=eps_r_Var, width=32, borderwidth=5)
eps_r_Entry.grid(row=7, column=1, columnspan=4, padx=10, pady=10)
def result_btn_function():
zl = impedanz_Var.get()
eps_r = eps_r_Var.get()
aus_d = aussenleiter_Var.get()
in_d = innenleiter_Var.get()
in_d = aus_d / (np.e ** (zl * 2 * np.pi * np.sqrt(eps_r) / z0))
r1 = np.sqrt(eps_r) * aus_d / 2
r = np.sqrt(eps_r) * in_d / 2
a = r1 / r
z = z0 / (2 * np.pi * np.sqrt(eps_r)) * np.log(aus_d / in_d)
f_g = etsi * (a + 1) / (2 * np.pi * np.sqrt(m0 * e0) * (r1 + r) * 1e-3) / 1e9
result = round(f_g, 2)
result1 = round(z, 2)
result2 = round(in_d, 2)
Result_label.config(text='f_g : ' + str(result))
Result_label1.config(text='Impedanz (Z) : ' + str(result1))
Result_label2.config(text='In.leiter D/O : ' + str(result2))
c0 = 299792458 # lichtgeschwindigkei
m0 = 4 * np.pi * 1e-7 # magnetische feldkonstante
e0 = 1 / (m0 * c0 ** 2) # elektrische feldkonstante
z0 = np.sqrt(m0 / e0) # frei raum wellen widerstan
zl = 30 # Impedanz
eps_r = 1 # Permitivity dry air 1.000594
aus_d = 4 # Aussenleiter
in_d = aus_d / (np.e ** (zl * 2 * np.pi * np.sqrt(eps_r) / z0))
# in_d = 0.11176 # Inneleiter
r1 = np.sqrt(eps_r) * aus_d / 2
r = np.sqrt(eps_r) * in_d / 2
a = r1 / r
z = z0 / (2 * np.pi * np.sqrt(eps_r)) * np.log(aus_d / in_d)
def wav_num(x):
return ((scs.jn(0, x * a) - scs.jn(2, x * a)) * (scs.yn(0, x) - scs.yn(2, x))
- (scs.yn(0, x * a) - scs.yn(2, x * a)) * (scs.jn(0, x) - scs.jn(2, x)))
x = np.arange(0.1, 1.0, 0.01)
test = wav_num(x)
etsi = sco.brentq(wav_num, 0.1, 0.8)
f_g = etsi * (a + 1) / (2 * np.pi * np.sqrt(m0 * e0) * (r1 + r) * 1e-3) / 1e9
plt.figure(1)
plt.plot(x, test)
plt.grid(True)
plt.show()
plt.savefig("result.png", dpi=199)
# Result btn
Result_btn = Button(root, command=result_btn_function, text="Result", bg="#145", fg="white", font=12)
Result_btn.grid(row=8, column=2, padx=10, pady=10)
# Show Result tkinter root window
Result_label = Label(root, text="", bg="#145", fg="white", font=14)
Result_label.grid(row=10, column=2, columnspan=20, padx=2, pady=2)
Result_label1 = Label(root, text="", bg="#145", fg="white", font=14)
Result_label1.grid(row=11, column=2, columnspan=20, padx=2, pady=2)
Result_label2 = Label(root, text="", bg="#145", fg="white", font=14)
Result_label2.grid(row=12, column=2, columnspan=20, padx=2, pady=2)
# clear btn soll entry fields räumen
clear_btn = Button(root, text="Clear", bg="#145", fg="white", font=12) #
clear_btn.grid(row=8, column=3, padx=10, pady=10)
'''
frage 2.
Radio btn muss Innenleiter field aktiv oder deaktivieren kann.
heißt wenn Radiobottun ausgeschaltet wird ( nur Innenleiter field deatktiviert werden muss )
'''
# Innenleiter btn muss Innenleiter field aktiv und deaktivieren
Radiobutton = Radiobutton(root, text="", variable=var,
font=12, bg="#145", fg="white", value=1) #command= ?
Radiobutton.grid(row=4, column=4, columnspan=4, padx=10, pady=10)
# Exit
exit_btn = Button(root, text="Exit", bg="#145", fg="white", font=12, command=root.quit)
exit_btn.grid(row=8, column=4, padx=10, pady=10)
print("TE11 cut-off f_g =", "%8.2f" % f_g, "GHz")
print("Die Impedanz Z =", "%8.2f" % z, "Ohm")
print("Innenleiter D/O =", "%8.2f" % in_d, "mm")
root = mainloop()
I am new here in the python forum and I try to write a program which I can do some calculations with.
programm run but i cant make the button alive like if its clicked, the entry widget will be inactive and when i click back again the entry widget get back to active mode.
and the plt.show() window is opened out of tkinter window. i need it in tkinter window and everytime i change the values the i must receive the updated window
thankyou so much for your response
the code is
from tkinter import *
from PIL import ImageTk, Image
import scipy as sc
import scipy.special as scs
import scipy.optimize as sco
import matplotlib.pyplot as plt
import numpy as np
root = Tk()
root.title("Coax TE Mode")
root.geometry("1400x1000")
root.config(background="#145")
var = IntVar()
# generate the window
title = Label(root, text="Coax TE Mode", font=('Helvetica', 22), bg="#145", fg="white")
title.grid(row=0, column=3, padx=20, pady=20)
leer = Label(root, text="", bg="#145", fg="#145") #abstand zwischen title und andere funktionen
leer.grid(row=1, column=1)
leer = Label(root, text="", bg="#145", fg="#145")
leer.grid(row=2, column=1)
# Impedanz = zl (in die gleichung als (z) gezeichnet)
impedanz_Label = Label(root, text="Impedanz", font=12, bg="#145", fg="white")
impedanz_Label.grid(row=6, column=0, padx=10, pady=10)
impedanz_Var = IntVar()
impedanz_Entry = Entry(root, textvariable=impedanz_Var, width=32, borderwidth=5, )
impedanz_Entry.grid(row=6, column=1, columnspan=4, padx=10, pady=10)
# Innenleiter = in_d (in die gleichung als (in_d) gezeigt)
innenleiter_Label = Label(root, text="Innenleiter", font=12, bg="#145", fg="white")
innenleiter_Label.grid(row=4, column=0, padx=10, pady=10)
innenleiter_Var = IntVar()
innenleiter_Entry = Entry(root, textvariable=innenleiter_Var, width=32, borderwidth=5)
innenleiter_Entry.grid(row=4, column=1, columnspan=4, padx=10, pady=10)
# Aussenleiter = aus_d (in die gleichung als (aus_d) gezeigt)
aussenleiter_Label = Label(root, text="Außenleiter", font=12, bg="#145", fg="white")
aussenleiter_Label.grid(row=5, column=0, padx=10, pady=10)
aussenleiter_Var = IntVar()
aussenleiter_Entry = Entry(root, textvariable=aussenleiter_Var, width=32, borderwidth=5)
aussenleiter_Entry.grid(row=5, column=1, columnspan=4, padx=10, pady=10)
# eps_r = in die gleichung als (eps_r) gezeigt
eps_r_Label = Label(root, text="eps_r", font=12, bg="#145", fg="white")
eps_r_Label.grid(row=7, column=0, padx=10, pady=10)
eps_r_Var = IntVar()
eps_r_Entry = Entry(root, textvariable=eps_r_Var, width=32, borderwidth=5)
eps_r_Entry.grid(row=7, column=1, columnspan=4, padx=10, pady=10)
def result_btn_function():
zl = impedanz_Var.get()
eps_r = eps_r_Var.get()
aus_d = aussenleiter_Var.get()
in_d = innenleiter_Var.get()
in_d = aus_d / (np.e ** (zl * 2 * np.pi * np.sqrt(eps_r) / z0))
r1 = np.sqrt(eps_r) * aus_d / 2
r = np.sqrt(eps_r) * in_d / 2
a = r1 / r
z = z0 / (2 * np.pi * np.sqrt(eps_r)) * np.log(aus_d / in_d)
f_g = etsi * (a + 1) / (2 * np.pi * np.sqrt(m0 * e0) * (r1 + r) * 1e-3) / 1e9
result = round(f_g, 2)
result1 = round(z, 2)
result2 = round(in_d, 2)
Result_label.config(text='f_g : ' + str(result))
Result_label1.config(text='Impedanz (Z) : ' + str(result1))
Result_label2.config(text='In.leiter D/O : ' + str(result2))
c0 = 299792458 # lichtgeschwindigkei
m0 = 4 * np.pi * 1e-7 # magnetische feldkonstante
e0 = 1 / (m0 * c0 ** 2) # elektrische feldkonstante
z0 = np.sqrt(m0 / e0) # frei raum wellen widerstan
zl = 30 # Impedanz
eps_r = 1 # Permitivity dry air 1.000594
aus_d = 4 # Aussenleiter
in_d = aus_d / (np.e ** (zl * 2 * np.pi * np.sqrt(eps_r) / z0))
# in_d = 0.11176 # Inneleiter
r1 = np.sqrt(eps_r) * aus_d / 2
r = np.sqrt(eps_r) * in_d / 2
a = r1 / r
z = z0 / (2 * np.pi * np.sqrt(eps_r)) * np.log(aus_d / in_d)
def wav_num(x):
return ((scs.jn(0, x * a) - scs.jn(2, x * a)) * (scs.yn(0, x) - scs.yn(2, x))
- (scs.yn(0, x * a) - scs.yn(2, x * a)) * (scs.jn(0, x) - scs.jn(2, x)))
x = np.arange(0.1, 1.0, 0.01)
test = wav_num(x)
etsi = sco.brentq(wav_num, 0.1, 0.8)
f_g = etsi * (a + 1) / (2 * np.pi * np.sqrt(m0 * e0) * (r1 + r) * 1e-3) / 1e9
plt.figure(1)
plt.plot(x, test)
plt.grid(True)
plt.show()
plt.savefig("result.png", dpi=199)
# Result btn
Result_btn = Button(root, command=result_btn_function, text="Result", bg="#145", fg="white", font=12)
Result_btn.grid(row=8, column=2, padx=10, pady=10)
# Show Result tkinter root window
Result_label = Label(root, text="", bg="#145", fg="white", font=14)
Result_label.grid(row=10, column=2, columnspan=20, padx=2, pady=2)
Result_label1 = Label(root, text="", bg="#145", fg="white", font=14)
Result_label1.grid(row=11, column=2, columnspan=20, padx=2, pady=2)
Result_label2 = Label(root, text="", bg="#145", fg="white", font=14)
Result_label2.grid(row=12, column=2, columnspan=20, padx=2, pady=2)
# clear btn soll entry fields räumen
clear_btn = Button(root, text="Clear", bg="#145", fg="white", font=12) #
clear_btn.grid(row=8, column=3, padx=10, pady=10)
'''
frage 2.
Radio btn muss Innenleiter field aktiv oder deaktivieren kann.
heißt wenn Radiobottun ausgeschaltet wird ( nur Innenleiter field deatktiviert werden muss )
'''
# Innenleiter btn muss Innenleiter field aktiv und deaktivieren
Radiobutton = Radiobutton(root, text="", variable=var,
font=12, bg="#145", fg="white", value=1) #command= ?
Radiobutton.grid(row=4, column=4, columnspan=4, padx=10, pady=10)
# Exit
exit_btn = Button(root, text="Exit", bg="#145", fg="white", font=12, command=root.quit)
exit_btn.grid(row=8, column=4, padx=10, pady=10)
print("TE11 cut-off f_g =", "%8.2f" % f_g, "GHz")
print("Die Impedanz Z =", "%8.2f" % z, "Ohm")
print("Innenleiter D/O =", "%8.2f" % in_d, "mm")
root = mainloop()