Nov-22-2020, 03:14 PM
Hi I'm new to python
I'm trying to create a widget that performs a calculation on clicking a button, only I want the function to open in a new window. can anyone help me please? as you can see I've put the function into button 1 but I don't know how to open it in a new window.
Thanks
I'm trying to create a widget that performs a calculation on clicking a button, only I want the function to open in a new window. can anyone help me please? as you can see I've put the function into button 1 but I don't know how to open it in a new window.
Thanks
import tkinter
from colorama import Fore, Back
import math
u = 3 #underlay
f = 2.5 #fitting
import sys
import os
from tkinter import *
master=tkinter.Tk()
master.title("Carpet shop")
master.geometry("400x500")
master.configure(bg='peach puff')
def callback():
w = float(input('carpet width:'))
l = float(input('carpet length:'))
p = float(input('carpet price:'))
p1 = w*l*p #carpet only
p4 = max(30,(w*l*f)) #fitting
p2 = w*l*p + max(30,(w*l*f)) #carpet and fitting
p3 = w*l*p + max(30,(w*l*f)) + w*l*u #carpet underlay and fitting
p5 = w*l*p + max(30,(w*l*f)) + w*l*u + 10 #carpet, underlay, grips and fitting
print( 'carpet only:£'"%.2f"%(p1))
print( 'fitting:£'"%.2f"%(p4))
print( 'carpet and fitting:£'"%.2f"%(p2))
print( 'carpet, underlay and fitting:£'"%.2f"%(p3))
print( 'carpet, underlay, grips and fitting:£'"%.2f"%(p5))
print( '********************************************')
button1=tkinter.Button(master, text="Carpet (rooms)",width=20,height=5,highlightbackground='red',bd=5, fg='red',command = callback)
button1.grid(row=1,column=3)
button2=tkinter.Button(master, text="Carpet (stairs)",width=20,height=5,highlightbackground='red',bd=5, fg='red')
button2.grid(row=3,column=3)
button3=tkinter.Button(master, text="Vinyl",width=20,height=5,highlightbackground='red',bd=5, fg='blue')
button3.grid(row=5,column=3)
button4=tkinter.Button(master, text="Laminate (area)",width=20,height=5,highlightbackground='red',bd=5, fg='green')
button4.grid(row=7,column=3)
button5=tkinter.Button(master, text="Laminate (rooms)",width=20,height=5,highlightbackground='red',bd=5, fg='green')
button5.grid(row=9,column=3)
master.mainloop()
