Python Forum
function in new window (tkinter)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function in new window (tkinter)
#1
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

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()
Reply


Messages In This Thread
function in new window (tkinter) - by Dale22 - Nov-22-2020, 03:14 PM
RE: function in new window (tkinter) - by Dale22 - Nov-23-2020, 04:50 PM
RE: function in new window (tkinter) - by Larz60+ - Nov-23-2020, 08:24 PM
RE: function in new window (tkinter) - by Dale22 - Nov-24-2020, 07:16 PM
RE: function in new window (tkinter) - by Larz60+ - Nov-24-2020, 08:08 PM
RE: function in new window (tkinter) - by Dale22 - Nov-24-2020, 09:36 PM
RE: function in new window (tkinter) - by Dale22 - Nov-24-2020, 11:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 486 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Using Tkinter inside function not working Ensaimadeta 5 5,021 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 837 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,703 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,900 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  Tkinter won't run my simple function AthertonH 6 3,830 May-03-2022, 02:33 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,913 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,576 Feb-17-2022, 07:02 AM
Last Post: pymn
  [Tkinter] tkinter best way to pass parameters to a function Pedroski55 3 4,832 Nov-17-2021, 03:21 AM
Last Post: deanhystad
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,839 Nov-07-2021, 05:14 PM
Last Post: gw1500se

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020