Create a male/female variable for an equation - python

I’m developing a BMI and fat percentage calculator for a school project. I took a model with a ready-made GUI and made the necessary adjustments, but I’m stuck in the equation to calculate the fat percentage.
This is my full code:
from tkinter import *
from tkinter import messagebox
def fazer_reset():
idade_tf.delete(0, 'end')
altura_tf.delete(0, 'end')
peso_tf.delete(0, 'end')
def calcular_imc():
kg = int(peso_tf.get())
m = int(altura_tf.get()) / 100
imc = kg / (m * m)
imc = round(imc, 1)
indice_de_imc(imc)
def indice_de_imc(imc):
if imc < 18.5:
messagebox.showinfo('IMC', f'IMC = {imc} está Abaixo do peso')
elif (imc > 18.5) and (imc < 24.9):
messagebox.showinfo('IMC', f'IMC = {imc} está Normal')
elif (imc > 24.9) and (imc < 29.9):
messagebox.showinfo('IMC', f'IMC = {imc} está Acima do peso')
elif (imc > 29.9):
messagebox.showinfo('IMC', f'IMC = {imc} está Obeso')
else:
messagebox.showerror('IMC', 'algo deu errado!')
def calcular_gordura():
idade = int(idade_tf.get())
kg = int(peso_tf.get())
m = int(altura_tf.get()) / 100
imc = kg / (m * m)
imc = round(imc, 1)
gordura = (1.2*imc)+(0.23*idade)-(10.8*sexo)-5.4
gordura = round(gordura, 1)
percentual_de_gordura(gordura)
def percentual_de_gordura(gordura):
messagebox.showinfo('Percentual de Gordura', f'O percentual de gordura é de {gordura} %')
ws = Tk()
ws.title('Calculadora de IMC, Percentual de Gordura e Massa Corporal')
ws.geometry('400x300')
ws.config(bg='#686e70')
var = IntVar()
frame = Frame(
ws,
padx=10,
pady=10
)
frame.pack(expand=True)
idade_lb = Label(
frame,
text="Idade"
)
idade_lb.grid(row=1, column=1)
idade_tf = Entry(
frame,
)
idade_tf.grid(row=1, column=2, pady=5)
sexo_lb = Label(
frame,
text='Sexo'
)
sexo_lb.grid(row=2, column=1)
frame2 = Frame(
frame
)
frame2.grid(row=2, column=2, pady=5)
masculino_rb = Radiobutton(
frame2,
text='Masculino',
variable=var,
value=1
)
masculino_rb.pack(side=LEFT)
feminino_rb = Radiobutton(
frame2,
text='Feminino',
variable=var,
value=0
)
feminino_rb.pack(side=RIGHT)
altura_lb = Label(
frame,
text="Altura (cm) "
)
altura_lb.grid(row=3, column=1)
peso_lb = Label(
frame,
text="Peso (kg) ",
)
peso_lb.grid(row=4, column=1)
altura_tf = Entry(
frame,
)
altura_tf.grid(row=3, column=2, pady=5)
peso_tf = Entry(
frame,
)
peso_tf.grid(row=4, column=2, pady=5)
frame3 = Frame(
frame
)
frame3.grid(row=5, columnspan=3, pady=10)
imc_btn = Button(
frame3,
text='IMC',
command=calcular_imc
)
imc_btn.pack(side=LEFT)
gordura_btn = Button(
frame3,
text='Gordura',
command=calcular_gordura
)
gordura_btn.pack(side=LEFT)
reset_btn = Button(
frame3,
text='Reset',
command=fazer_reset
)
reset_btn.pack(side=LEFT)
sair_btn = Button(
frame3,
text='Sair',
command=lambda: ws.destroy()
)
sair_btn.pack(side=RIGHT)
ws.mainloop()
The equation I use to calculate fat percentage is: fat percentage = (1.2 * IMC) + (0.23 * idade) -(10.8 * sexo) - 5.4. ‘IMC’ is BMI, ‘idade’ is age and ‘sexo’ is gender.
def calcular_gordura():
idade = int(idade_tf.get())
kg = int(peso_tf.get())
m = int(altura_tf.get()) / 100
imc = kg / (m * m)
imc = round(imc, 1)
gordura = (1.2*imc)+(0.23*idade)-(10.8*sexo)-5.4
gordura = round(gordura, 1)
percentual_de_gordura(gordura)
In ‘sexo’, I wanted the value assigned to be 1 if it’s male and 0 if it’s female.
The GUI I got uses two radio buttons: One for Masculino (Male) and one for Feminino (Female). But I’m not able to make them functional for the fat percentage equation.
masculino_rb = Radiobutton(
frame2,
text='Masculino',
variable=var,
value=1
)
masculino_rb.pack(side=LEFT)
feminino_rb = Radiobutton(
frame2,
text='Feminino',
variable=var,
value=0
)
feminino_rb.pack(side=RIGHT)
I tried to create an if and else condition, but I can't make the code understand the radio button selection.

The radio button values are being assigned to the variable var in your example. However, you need to extract the value by using var.get().
With this information in mind, you could set the sexo variable to be equal to var.get().
...
def calcular_gordura():
sexo = var.get()
idade = int(idade_tf.get())
kg = int(peso_tf.get())
m = int(altura_tf.get()) / 100
imc = kg / (m * m)
imc = round(imc, 1)
gordura = (1.2*imc)+(0.23*idade)-(10.8*sexo)-5.4
gordura = round(gordura, 1)
percentual_de_gordura(gordura)
...

Related

problem with the checkbox in python, the checkbox don't give me a value

yesterday i wrote this program, i started programming with python recently. i decided to do a program with the gui, a program for the ordering of the panini and use the qrcode for read what is the order, i used tkinter and pyqrcode as u can see in the code. i think that the problem is the checkbox, because it does not give me any result, so the qr code is null and the code dont work. i 'm here for help to solve this problem and some suggestions to improve programming, thanks
import tkinter as tk
window = tk.Tk()
window.geometry("500x500")
window.title("Ordina panino")
window.resizable(False,False)
window.configure(background='Yellow')
frame=tk.Frame(window) #frame panino 1
frame.pack(side = tk.TOP, pady= 20)
frame2=tk.Frame(window) #frame descrizione panino 1
frame2.pack(side = tk.TOP)
frame3=tk.Frame(window) #frame panino 2
frame3.pack(side = tk.TOP, pady= 20)
frame4=tk.Frame(window) #frame descrizione panino 2
frame4.pack(side = tk.TOP)
frame5=tk.Frame(window) #frame panino 3
frame5.pack(side = tk.TOP, pady= 20)
frame6=tk.Frame(window) #frame descrizione panino 3
frame6.pack(side = tk.TOP)
frame7=tk.Frame(window, pady= 20) #frame panino 4
frame7.pack(side = tk.TOP)
frame8=tk.Frame(window) #frame descrizione panino 4
frame8.pack(side = tk.TOP)
frame9=tk.Frame(window, pady=20) #frame Bottone
frame9.pack(side = tk.TOP)
#//////////////////////////////////////// PANINO1
CheckVar1 = tk.IntVar()
radiobutton1= tk.Checkbutton(frame, variable= CheckVar1, padx= 10, )
radiobutton1.pack( side = tk.LEFT )
panino1 = tk.Label(frame, text = 'panino1', padx=20)
panino1.pack( side = tk.LEFT)
numeropanini1 =tk.Spinbox(frame,from_=0, to=10)
numeropanini1.pack( side = tk.RIGHT )
testodescpanino1= "Ingredienti panino 1: ###############,##########,\n #############,##########"
descrizionepanino1 = tk.Label(frame2, text = testodescpanino1)
descrizionepanino1.pack( side = tk.TOP)
#//////////////////////////////////////// PANINO 2
CheckVar2 = tk.IntVar()
radiobutton2= tk.Checkbutton(frame3, variable = CheckVar2, padx=10)
radiobutton2.pack( side = tk.LEFT )
panino2 = tk.Label(frame3, text = 'panino2', padx= 20)
panino2.pack( side = tk.LEFT)
numeropanini2 =tk.Spinbox(frame3, from_=0, to=10)
numeropanini2.pack( side = tk.RIGHT )
testodescpanino2= "Ingredienti panino 2: ###############,##########,\n #############,##########"
descrizionepanino2 = tk.Label(frame4, text = testodescpanino2)
descrizionepanino2.pack( side = tk.TOP)
#//////////////////////////////////////// PANINO 3
CheckVar3 = tk.IntVar()
radiobutton3= tk.Checkbutton(frame5, variable= CheckVar3, padx=10)
radiobutton3.pack( side = tk.LEFT )
panino3 = tk.Label(frame5, text = 'panino3', padx=20)
panino3.pack( side = tk.LEFT )
numeropanini3 =tk.Spinbox(frame5, from_=0, to=10)
numeropanini3.pack( side = tk.RIGHT )
testodescpanino3= "Ingredienti panino 3: ###############,##########,\n #############,##########"
descrizionepanino3 = tk.Label(frame6, text = testodescpanino3)
descrizionepanino3.pack( side = tk.TOP)
#//////////////////////////////////////// PANINO 4
CheckVar4 = tk.IntVar()
radiobutton4= tk.Checkbutton(frame7, variable= CheckVar4, padx=20)
radiobutton4.pack( side = tk.LEFT )
panino4 = tk.Label(frame7, text = 'panino4', padx=10)
panino4.pack( side = tk.LEFT )
numeropanini4 =tk.Spinbox(frame7, from_=0, to=10)
numeropanini4.pack( side = tk.RIGHT )
testodescpanino4= "Ingredienti panino 4: ###############,##########,\n #############,##########"
descrizionepanino4 = tk.Label(frame8, text = testodescpanino4)
descrizionepanino4.pack( side = tk.TOP)
def prezzototale():
stringaqr = ""
i = ""
if CheckVar1.get() == 1:
i = numeropanini1.get()
stringaqr = str(i) + stringaqr + str(panino1.cget("text"))
if CheckVar2.get() == 1:
i = numeropanini2.get()
stringaqr = str(i) + stringaqr + str(panino2.cget("text"))
if CheckVar3.get() == 1:
i = numeropanini3.get()
stringaqr = str(i) + stringaqr + str(panino3.cget("text"))
if CheckVar4.get() == 1:
i = numeropanini4.get()
stringaqr = str(i) + stringaqr + str(panino4.cget("text"))
print(stringaqr)
QRstr = stringaqr
url = pyqrcode.create(QRstr)
url.png('qrordine.png', scale=8)
button = tk.Button(frame9, text = "Pronto!", command = prezzototale())
button.pack( side = tk.TOP )
window.mainloop()
button = tk.Button(frame9, text = "Pronto!", command = prezzototale()) is not correct. The command should have no parenthesis. Try button = tk.Button(frame9, text = "Pronto!", command = prezzototale)

The horizontal scroll bar is not working properly, treeview - python

I have a problem with scrolling the horizontal bar. When I add another column is the whole
I'm leaving the window in which I display it. Is it possible to set the size of the treeview permanently and scroll the columns with the horizontal bar?
The screen may be too small at present. To display the data content.
Here is my source
def wczytaj_dane(page):
ok = Toplevel()
width_of_window = 1030
height_of_window = 570
screen_width = ok.winfo_screenwidth()
screen_height = ok.winfo_screenheight()
x_coordinate = (screen_width/2) - (width_of_window/2)
y_coordinate = (screen_height/2) - (height_of_window/2)
ok.geometry("%dx%d+%d+%d" % (width_of_window, height_of_window, x_coordinate, y_coordinate))
"""Polączenie z bazą danych oraz pobieranie danych"""
connection = pymysql. connect ( host = '192.168.10.100' ,
database = 'tester_produkcja' ,
user = 'marcin' ,
password = 'marcin96' )
try:
with connection . cursor () as cursor :
sql= "SELECT * FROM `Historia` WHERE `Poczernin_kod_Produktu`='DP^8E0E1^0005'"
cursor.execute ( sql,)
result_dpcode = cursor.fetchall () #fetchone ()
""" zamiana krotki(tuple) na liczbę całkowitą"""
#result_dp = int(result_dpcode[0])
finally:
connection.close()
tree = ttk.Treeview(ok,height=5)
tree["columns"]=("one","two","three","four","five","six","seven","eight","nine","ten","ten1","ten2","ten3","ten4","ten5",
"ten6","ten7")
tree.column("#0", width=40)
tree.column("one", width=100 )
tree.column("two", width=50)
tree.column("three", width=220)
tree.column("four", width=50 )
tree.column("five", width=50)
tree.column("six", width=50)
tree.column("seven", width=50)
tree.column("eight", width=50)
tree.column("nine", width=50)
tree.column("ten", width=50)
tree.column("ten1", width=50)
tree.column("ten2", width=70)
tree.column("ten3", width=70)
tree.column("ten4", width=125)
tree.column("ten5", width=120)
tree.column("ten6", width=100)
tree.column("ten7", width=100)
tree.heading("#0", text="Lp.")
tree.heading("one", text="Godzina/Data")
tree.heading("two", text="KTM")
tree.heading("three",text="Nazwa Produktu")
tree.heading("four",text="Funkcja")
tree.heading("five",text="PW")
tree.heading("six", text="VAC")
tree.heading("seven",text="WATT")
tree.heading("eight",text="ŁAD")
tree.heading("nine",text="ROZŁ")
tree.heading("ten",text="VDC")
tree.heading("ten1",text="Uwagi")
tree.heading("ten2",text="Pracownik")
tree.heading("ten3",text="Inspektor")
tree.heading("ten4",text="Poprawność Montażu")
tree.heading("ten5",text="Wygląd zewnętrzny")
tree.heading("ten6",text="Wygląd zewnętrzny")
tree.heading("ten7",text="Wygląd zewnętrzny")
cpt = 0
for row in result_dpcode:
tree.insert('','end', text=str(cpt), values=(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],
row[9],row[10],row[11],row[12],row[13],row[14],row[15] ))
cpt +=1
ysb = ttk.Scrollbar (ok, orient = 'vertical', command = tree.yview)
xsb = ttk.Scrollbar (ok, orient = 'horizontal', command = tree.xview)
tree.grid(row=0,column=0)
ysb.grid (row = 0, column = 1, sticky = N+S)
xsb.grid (row = 1,column = 0, sticky = E+W)
tree.configure (yscroll = ysb.set)
tree.configure (xscroll = xsb.set)

python label don't updating in realtime [duplicate]

This question already has answers here:
Why is my Button's command executed immediately when I create the Button, and not when I click it? [duplicate]
(5 answers)
Closed 4 years ago.
I addressed issues with the same problem and the solution was mainly in .set ().
I am a novice, I did the same and I did not succeed. Please help understand and point out the error.
I do so that in dp1o the value changes according to the formula xmax, but it seems that the calculation occurs only for an automatically assigned zero.
from math import *
from tkinter import *
root = Tk()
f_top = Frame(root)
root.title('Полет ядра')
g = 9.81
dx = 0.01
v = IntVar()
an = IntVar()
t = IntVar()
vx = IntVar()
def analysis():
v = int(entry1.get())
an = int(entry2.get())
t = (((2 * v * sin(an)) / g))
vx = v * cos(an)
xmax = vx * t * cos(an)
dp1o.config(text=xmax)
first = LabelFrame(root, text='Данные для первого графика')
first.pack(side='left')
second = Label(first, text='Начальная скорость')
second.pack()
entry1 = Entry(first, width=10, textvariable=v)
entry1.pack()
third = Label(first, text='Угол выстрела')
third.pack()
entry2 = Entry(first, width=10, textvariable=an)
entry2.pack()
first = LabelFrame(root, text='Расчет')
first.pack(side='right')
dp1 = Label(first, text='Дальность полета 1 тела')
dp1.pack()
dp1o = Label(first, text='')
dp1o.pack()
button = Button(root, text="Сгенерировать", command=analysis())
button.pack(side='left')
root.mainloop()
Your problem is that you passed () after analysis. When dealing with command there is no need to put () after the function you are calling.
Here is a working version of your code.
from math import *
from tkinter import *
root = Tk()
f_top = Frame(root)
root.title('Полет ядра')
g = 9.81
dx = 0.01
v = IntVar()
an = IntVar()
t = IntVar()
vx = IntVar()
def analysis():
v = int(entry1.get())
an = int(entry2.get())
t = (((2 * v * sin(an)) / g))
vx = v * cos(an)
xmax = vx * t * cos(an)
dp1o.config(text=xmax)
first = LabelFrame(root, text='Данные для первого графика')
first.pack(side='left')
second = Label(first, text='Начальная скорость')
second.pack()
entry1 = Entry(first, width=10, textvariable=v)
entry1.pack()
third = Label(first, text='Угол выстрела')
third.pack()
entry2 = Entry(first, width=10, textvariable=an)
entry2.pack()
first = LabelFrame(root, text='Расчет')
first.pack(side='right')
dp1 = Label(first, text='Дальность полета 1 тела')
dp1.pack()
dp1o = Label(first, text='')
dp1o.pack()
button = Button(root, text="Сгенерировать", command=analysis)
button.pack(side='left')
root.mainloop()

How to add a $ sign in front of the amounts?

The code I show hereunder has got some if statements which make different variables which all involve money. When I run the code I can select how many of any drink and if it is takeaway or not.
IF it iss takeaway it adds 5% to the cost and if there are more than 3 drinks it takes 10% off the invoice.
Could anyone help me add a +$ for the takeaway on the output area of gui and a -$ for the discount.
Any help would be appreciated.
If anyone wants to see the entire code, it is visible in this gist
import tkinter as tk
import time
import random
root = tk.Tk()
root.geometry("1600x8000")
root.title("Cafe au Lait")
tops = tk.Frame(root, width=1600, relief="sunken")
tops.pack(side="top")
f1 = tk.Frame(root, width=800, height=700, relief="sunken")
f1.pack(side="left")
latte = tk.DoubleVar()
double_expresso = tk.DoubleVar()
iced = tk.DoubleVar()
cost = tk.DoubleVar()
cappacuino = tk.DoubleVar()
expresso = tk.DoubleVar()
flat_white = tk.DoubleVar()
total = tk.DoubleVar()
takeaway_var = tk.StringVar()
rand = tk.IntVar()
discount = tk.DoubleVar()
takeaway = tk.DoubleVar()
def ref(even=None):
x=random.randint(10000,99999)
randomRef=str(x)
rand.set(randomRef)
global total, cost
if latte.get() == "":
col = 0
else:
col = latte.get()
if iced.get() == "":
coi = 0
else:
coi = iced.get()
if flat_white.get() == "":
cofw = 0
else:
cofw = flat_white.get()
if double_expresso.get() == "":
code = 0
else:
code = double_expresso.get()
if cappacuino.get() == "":
coc = 0
else:
coc = cappacuino.get()
if expresso.get() == "":
coe = 0
else:
coe = expresso.get()
costoflatte = col * 3.5
costoficed = coi * 2.5
costofflat_white = cofw * 3.75
costofdouble_expresso = code * 4.25
costofcappacuino = coc * 3.75
costofexpresso = coe * 3
total.set('{}'.format(cost.get() + costoflatte + costoficed + costofflat_white + costofdouble_expresso + costofcappacuino + costofexpresso))
cost.set('{}'.format(cost.get() + costoflatte + costoficed + costofflat_white + costofdouble_expresso + costofcappacuino + costofexpresso))
if txt_takeaway.get() in ['Yes', 'yes', 'y', 'Y']:
w = total.get()
takeaway.set(w * 0.05)
if txt_takeaway.get() in ['Yes', 'yes', 'y', 'Y']:
x = total.get()
total.set((x * 0.05) + x)
if (coc + col + coi + cofw + code + coe) >=3:
z = total.get()
discount.set(z * 0.1)
if (coc + col + coi + cofw + code + coe) >=3:
y = total.get()
total.set(y * 0.9)
The code above sets it all up so that the code below outputs corrdctly. It is needed to run. The first 2 buttons below are the ones that need the +$ and -$ added to.
lbl_takeaway= tk.Label(f1, font=('arial', 16, 'bold'),text="Takeaway",bd=16,anchor="w").grid(row=2, column=2)
txt_takeaway=tk.Entry(f1, font=('arial',16,'bold'),textvariable=takeaway,bd=10,insertwidth=4,bg="powder blue",justify='right')
txt_takeaway.grid(row=2,column=3)
lbl_discount= tk.Label(f1, font=('arial', 16, 'bold'),text="Discount",bd=16,anchor="w").grid(row=3, column=2)
txt_discount=tk.Entry(f1, font=('arial',16,'bold'),textvariable=discount,bd=10,insertwidth=4,bg="powder blue",justify='right')
txt_discount.grid(row=3,column=3)
tk.Label(f1, font=('arial', 16, 'bold'),text="Order Number",bd=16,anchor="w").grid(row=0, column=2)
txt_order=tk.Entry(f1, font=('arial',16,'bold'),textvariable=rand,bd=10,insertwidth=4,bg="powder blue",justify='right')
txt_order.grid(row=0,column=3)
tk.Label(f1, font=('arial', 16, 'bold'), text="Takeaway", bd=16, anchor="w").grid(row=6, column=0)
txt_takeaway = tk.Entry(f1, font=('arial',16,'bold'),textvariable=takeaway_var, bd=10, insertwidth=4, bg="powder blue", justify='right')
txt_takeaway.grid(row=6, column=1)
tk.Label(f1, font=('arial', 16, 'bold'), text="Cost of Order", bd=16, anchor="w").grid(row=1, column=2)
txt_cost = tk.Entry(f1, font=('arial',16,'bold'), textvariable=cost,bd=10, insertwidth=4, bg="powder blue", justify='right')
txt_cost.grid(row=1, column=3)
tk.Label(f1, font=('arial', 16, 'bold'), text="Total Cost", bd=16, anchor="w").grid(row=5, column=2)
txt_totalcost = tk.Entry(f1, font=('arial',16,'bold'), textvariable=total, bd=10, insertwidth=4, bg="powder blue", justify='right')
txt_totalcost.grid(row=5, column=3)
tk.Label(f1, font=('arial', 16, 'bold'),text="Latte",bd=16,anchor="w").grid(row=1, column=0)
txt_latte=tk.Entry(f1, font=('arial',16,'bold'),textvariable=latte,bd=10,insertwidth=4,bg="powder blue",justify='right')
txt_latte.grid(row=1,column=1)
btnTotal=tk.Button(f1,padx=16,pady=8,bd=16,fg="black",font=('arial',16,'bold'),width=10,text="Total",bg="powder blue",command=ref).grid(row=7,column=1)
root.bind("<Return>", ref)
root.mainloop()
You can insert a default value in the entry field; here is a little example that subclasses tk.Entry, that you can reuse in your own project:
import tkinter as tk
class EntryBoxWithNegativeDollarSign(tk.Entry):
def __init__(self, master, *args, **kwargs):
self.master = master
super().__init__(self.master, *args, **kwargs)
self.default = '-$'
self.insert(0, self.default)
self.pack()
def set_default(self):
self.delete('0',tk.END)
self.insert(0, self.default)
def get(self):
value = - float(super().get()[2:])
self.set_default()
print(value)
return value
root = tk.Tk()
app = tk.Frame(root)
app.pack()
entry = EntryBoxWithNegativeDollarSign(app)
tk.Button(app, text='get value', command=entry.get).pack()
root.mainloop()

tkinter labels dont show

So I got the assignment to make a small Bingo App (Windows btw) after I followed a few webinars on Tkinter GUI and some Googling.
I have made successfull little apps that worked correctly, but this time I try to make it with knowledge I think I have.
Anyway, in that Bingo app, I want 50 labels that represent 50 numbers of the Bingo card, 5 rows of 10 numbers.
I know how to align them, but they need to show up first.
Can you look at my code and assess what I do wrong?
Ignore the many Dutch comments :)
'''
iWMMMM0.
XM#o:..iIMM.
MM. :XC17, YM8
M# v#9. .W# ,M,
#M 7#i ,0$: M0 MM
.M. #7 M#t, ME MQ
MM iM. #$Ci$Q ;M#CCY:.
CM ,M, b#$; v;7IEW#MMM#1
MQ WQ .tE0Q2nCCYc;i,:7#MMi
:M #b . .. .:YCb0U: YMM.
WM E#i .... ,i: ,b#; bMQ,SbW06i
oM MC ... MME9#$Y . .#b SM#b2tob#MM1
Mi #7 ... #M .v iMt ... #X :CoUzt: :MM, nWM#Bc :nQ#$Ui
M: #Y .. M9 MM# b# ... Zb1#Zi. .;Z#Y SMi MM#t;vCMM,CMM0C77bMM8
M, #7 .. #6 Y7 ;Mn ... #QB. ,#b ZM MM .n9U; bMM. ;z2U7 MM
M: #Y ., #9.;tQQv ... ;MQ, :#; Mv MM X$: M; , ;$2. 7#i M8
M: #7 .. #BW1i ..,:Y$Mt$ MX MMtiEM: E#: ZME,.W$c ; c# .M
M: #Y ., ME .. .ZMM8o89 QM. i;U## .Zb7: ,BBYzQ bM# Mi M
Mi #X .. M, iMM#WS :bWQb, ,#M1;IoIX 1#c bMMX iM I#E$CM M, M
.MM #7 ., Mn EM8AEE#: . v$AWQ#$Q#MMIWz, ;$Z$ MMzW2 M# $ZY$C bM CM
MZ ib#i .. ##. ;t $z#. ., CWUWnE$b7: :Y #$c MEYY .MM8 :; vM. M1
iM iMi .., #bWI,..M#i#C .., Mv i#E. UMM2 #BC oC;tMMCES .#M MM
MY E0 ... S#i:Z$MZ .Mv ... M8 7WEz MnZo #obUA: ic.7bEW$#M#C iMM
CMi I#; .. b#; $$ ... ,MQ 7$Zz #zbz #IXW#E69z. 80 ::iAMM;
iM$ .$Qi . :Z$Q0Q#6. ... MQ0 C$b1 MtQ7 YZWW,.c$## MC MMM#b.
MM7 iBWv. .., .M#7$ v$8; vQ0:iCAM: :#bM0 nMU BM
:MM1 .6$Q7: ;MMS:Q7 ##i12EMzEESB# .7:,,2M# MM
,MM#: ,1E$BQbZ6EBMM#; iQQ##B$72n7i.,vo tQQIZQ$WC .#MQ
6MM#o;,,:ivY;i,,iEMM...,,:iC2Q#MMMQ$M$..,i::,;9MMZ
YIEbEAU269086, ;Bb08bAz;:. 7QbEZb8boi
'''
##Basale geimporteerde functies
from tkinter import*
#self=()
#Importeert de randomfucntie
#import random
#Importeert de Python Debugger
#Runnen met pdb.run
#import pdb
#Importeert de PIL Python Image Library
#from PIL import Image, ImageTK
#image = image.open("bestandsnaam.jpg")
#photo ImageTK.PhotoImage(image)
#Een afbeelding op een label
#label = Label(image=photo(als photo de naam van de variable is))
#label.image = photo (bewaren als referentie?<- geen idee nog)
'''
#=# Start van metainfo class/klasse
class MetaBingPy():
def __init__(self):
super(MetaBingPy, self).__init__()
self.parent = parent
self.pack()
MetaBingPy.BingoPyC(self)
##Functie voor random number generator
def BingoPyC:
self.root = Tk()
self.root.title("Python Bingo")
#=#Einde metainfo class
'''
###def random.randint(1,50)
#####of# randrange(1,50)
##GUI voor BingPy, moet root heten. Geen eigen naam, zoals:
##BingPyGUI wat ik had.
root = Tk()
root.wm_title("Bingo Python")
root.wm_maxsize("800","600")
root.wm_minsize("800","600")
#root.wm_grid(baseWidth="800", baseHeight="800")
#root.grid("800x800")
#_tkinter.TclError: wrong # args: should be "wm grid window ?baseWidth baseHeight
#widthInc heightInc?"
##self.title="Bingo Python"
###GUI voor BingPy code, altijd afsluiten met:
###bovenaan
root.mainloop()
'''
#Algemene Python Bingo klasse
class BingoPy
def
'''
#Labels voor alle nummers (50)
label1 = Label(root, text="1jghjgjkhjhg")
label1.grid()
label1.pack()
label2 = Label(root, text="2")
label2.grid()
label2.pack()
label3 = Label(root, text="3")
label3.grid()
label3.pack()
label4 = Label(root, text="4")
label4.grid()
label4.pack()
label5 = Label(root, text="5")
label5.grid()
label5.pack()
label6 = Label(root, text="6")
label6.grid()
label6.pack()
label7 = Label(root, text="7")
label7.grid()
label7.pack()
label8 = Label(root, text="8")
label8.grid()
label8.pack()
label9 = Label(root, text="9")
label9.grid()
label9.pack()
label10 = Label(root, text="10")
label10.grid()
label10.pack()
label11 = Label(root, text="11")
label11.grid()
label11.pack()
label12 = Label(root, text="12")
label12.grid()
label12.pack()
Label13 = Label(root, text="13")
Label13.grid()
Label13.pack()
label14 = Label(root, text="14")
label14.grid()
label14.pack()
label15 = Label(root, text="15")
label15.grid()
label15.pack()
label16 = Label(root, text="16")
label16.grid()
label16.pack()
label7 = Label(root, text="17")
label17.grid()
label17.pack()
label18 = Label(root, text="18")
label18.grid()
label18.pack()
label19 = Label(root, text="19")
label19.grid()
label19.pack()
label20 = Label(root, text="20")
label20.grid()
label20.pack()
label21 = Label(root, text="21")
label21.grid()
label21.pack()
label22 = Label(root, text='22')
label22.grid()
label22.pack()
label23 = Label(root, text="23")
label23.grid()
label23.pack()
label24 = Label(root, text="24")
label24.grid()
label24.pack()
label25 = Label(root, text="25")
label25.grid()
label25.pack()
label26 = Label(root, text="26")
label26.grid()
label26.pack()
label27 = Label(root, text="27")
label27.grid()
label27.pack()
label28.Label(root, text="28")
label28.grid()
label28.pack()
label29 = Label(root, text="29")
label29.grid()
label29.pack()
label30 = Label(root, text="30")
label30.grid()
label30.pack()
label31 = Label(root, text="31")
label31.grid()
label31.pack()
label32 = Label(root, text="32")
label32.grid()
label32.pack()
label33 = Label(root, text="33")
label33.grid()
label33.pack()
label34 = Label(root, text="34")
label34.grid()
label34.pack()
label35 = Label(root, text="35")
label35.grid()
label35.pack()
label36 = Label(root, text="36")
label36.grid()
label36.pack()
label37 = Label(root, text="37")
label37.grid()
label37.pack()
label38 = Label(root, text="38")
label38.grid()
label38.pack()
label39 = Label(root, text="39")
label39.grid()
label39.pack()
label40 = Label(root, text="40")
label40.grid()
label40.pack()
label41 = Label(root, text="41")
label41.grid()
label41.pack()
label42 = Label(root, text="42")
label42.grid()
label42.pack()
label43 = Label(root, text="43")
label43.grid()
label43.pack()
label44 = Label(root, text="44")
label44.grid()
label44.pack()
label45 = Label(root, text="45")
label45.grid()
label45.pack()
label46 = Label(root, text="46")
label46.grid()
label46.pack()
label47 = Label(root, text="47")
label47.grid()
label47.pack()
label48 = Label(root, text="48")
label48.grid()
label48.pack()
label49 = Label(root, text="49")
label49.grid()
label49.pack()
label50 = Label(root, text="50")
label50.grid()
label50.pack()
#Maakt het rood (en als het mogelijk is: doorstrepen) als het getrokken is
#Waarde-return in veld + niet meer zelfde nummer kunnen kiezen
#--------------------------------------------------------------------------
#Knoppen voor afsluiten en nieuw getal
##Afsluiten
#def bingoclose():
# print("Bingo Afsluiten")
'''
bAfsluiten = Button(root,text"Sluit Bingo Af")
bAfsluiten.pack()
'''
'''
{
'title' : ['BingPy'],
'summary' : ['Simple Bingo Python Application with rand.num generator'],
'authors' : ['Thomas']
#'date' : ['2015']
'base_url' : ['http://www.rainydays.eu']
}
'''
'''
Info en weblinks:
https://docs.python.org/3/library/random.html?highlight=random#module-random
http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf (Python 2.7!)
https://wiki.scinet.utoronto.ca/wiki/images/4/41/Pwcgui.pdf
http://stackoverflow.com/questions/3643235/how-to-add-a-margin-to-a-tkinter
-window Margins in Python (padx, pady)
'''
You need to learn about data structures, like list.
You had root.mainloop() early on in the code. That starts a loop. Nothing after that is executed until the window is closed, which means it has to be at the end.
Choose one geometry manager. You can't use both grid() and pack() in the same parent widget, much less on the same child widget.
You had some typos, like label7 = instead of label17 =, and label28.Label instead of label28 = Label. Most of these would never have happened if you had used a list.
Obviously, 50 labels won't fit in a single column in a window of that size. You've got some decisions ahead of you involving window size, label placement, possible scrollbar, and so on.
The resulting code taking into account all these points (except the last) is shown below.
from tkinter import *
root = Tk()
root.wm_title("Bingo Python")
root.wm_maxsize("800","600")
root.wm_minsize("800","600")
labels = [Label(root, text=i) for i in range(1, 51)]
for label in labels:
label.pack()
root.mainloop()

Categories