FULL CODE
Here is the complete code, I don't know if I made a mistake in some things, if so please correct me. I am making a menu of 4 options, this is the first option:
import numpy
from tkinter import *
import tkinter as tk
from tkinter import messagebox
ventas = numpy.array ( [ [ [ 24,45,44,40,37,70,80 ] ,
[ 33,45,32,55,46,75,90 ] ,
[ 45,40,37,38,40,80,85 ] ] ,
[ [ 40,41,38,42,38,90,75 ] ,
[ 39,39,42,40,42,88,98 ] ,
[ 41,41,44,36,38,98,90 ] ] ,
[ [ 24,45,44,40,37,95,82 ] ,
[ 33,45,32,55,46,97,98 ] ,
[ 45,40,37,38,40,98,98 ] ] ,
[ [ 40,41,38,42,38,90,50 ] ,
[ 39,39,42,40,42,80,78 ] ,
[ 41,41,44,36,38,50,70 ] ] ] )
vendedores = numpy.array([ " Juan Perez " , " María Acuña " , " Pedro Fuentes " ] )
def sacar_promedio():
total=[]
tra=ventas[semana.get()-1,trabajador.get()-1]
total.append(tra)
if semana.get() == 1:
total1 = ((numpy.sum(numpy.array(total)*1000)))
total2 = ((((numpy.sum(numpy.array(total)*1000)))/7))
elif semana.get() == 2:
total1 = ((numpy.sum(numpy.array(total)*1000)))
total2 = ((((numpy.sum(numpy.array(total)*1000)))/7))
elif semana.get() == 3:
total1 = ((numpy.sum(numpy.array(total)*1000)))
total2 = ((((numpy.sum(numpy.array(total)*1000)))/7))
else:
total1 = ((numpy.sum(numpy.array(total)*1000)))
total2 = ((((numpy.sum(numpy.array(total)*1000)))/7))
mensaje.set("El promedio semanal del trabajador es: "+ str(round(total2)))**texto en negrita**
mensaje2.set("El total semanal del trabajador es: "+str(round(total1)))**texto en negrita**
win = Tk()
win = tk.Toplevel()
win.title("La Favorita")
win.geometry('800x300')
win.config(bg="dark turquoise")
e5 = tk.Label(win, text="Resultado final")
e5.pack(side=tk.TOP)
etiquetaa = Label(win, textvariable=mensaje).place(x=100, y=150)
etiquetaa2 = Label(win, textvariable=mensaje2).place(x=100, y=200)
ventana = Tk()
ventana.title("La Favorita")
ventana.config(bg="dark turquoise")
ventana.geometry('800x500')
etiqueta1= Button(ventana, text="1-total semanal vendido y promedio semanal del trabajador", command=sacar_promedio).place(x=30, y=0)** aqui quiero que me calcule todo**
semana = IntVar()
trabajador = IntVar()
mensaje = StringVar()
mensaje2 = StringVar()
etiqueta = Label(ventana, text="Selecciona una semana").place(x=20, y=150)
ola = Spinbox(ventana, from_=1, to=4, textvariable=semana).place(x=300, y=150)
boton2 = Button(ventana, text="resultado", command=sacar_promedio).place(x=100, y=250)
etiquetaL = Label(ventana, text="Seleccione trabajador:").place(x=20, y=200)
ola2 = Spinbox(ventana, from_=1, to=3, textvariable=trabajador).place(x=300, y=200)
ventana.mainloop()
I want to put this window inside another window with a 'Button' that gives me the result of the worker and the week I want, I don't know very well, I accept advice, thanks.
I tried it and it runs fine, but a small window still comes out that I don't know what it is, if you could guide me I would appreciate it.
Good day,
The extra little window comes out because you are creating a new main window with:
To create sub-windows you must use
Toplevel
as you do in the line following the wrong line mentioned above.By commenting/removing the wrong line your program works correctly.
Additional Information:
When importing a package it is recommended not to import all the content in this way:
Since if there were functions with the same name as some standard function of
Python
or another module that we were using, then the one from the last imported library would be used. It is better to import the modules and assign them an alias, as follows:Now, I don't understand why you put the following 3 lines:
First you are importing all the components of
tkinter
then you importtkinter otra vez pero le das un alias y por último importas únicamente
messageboxde
tkinter. La línea de enmedio sería la única que necesitas y por lo tanto todos los elementos de
tkinterdeberían iniciar con
tk.`For example, instead of:
Would
Lastly, the comments in
Python
are started with the hash (#
), not the asterisk, that caused your example to not run and errors to appear when trying to solve your problem.Full example: