Python Forum
tkinter checkbutton if checked
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter checkbutton if checked
#1
Hi - I am learning python and need help with this code. I have researched online, but haven't been able to find an answer for what I'm looking for.

My code is below. The 'open' function is what I need help with. I am looking to add the fooditem selected to the newwindow if the checkbox is checked. My code is below but isn't working. Can someone help point me in the right direction?

fooditems = ['pizza','breadsticks','wings','CocaCola','brownie']
fooditems2 = []
price = ['15', '5', '10', '3', '2']
quantity = ['1','2','3','4']

import tkinter as tk
from tkinter import *
from tkinter import ttk

menu = Tk()
menu.geometry('500x300')

combobox = ttk.Combobox(menu, values=quantity)

def Open():
    New_Window = Tk()
    New_Window.geometry('500x300')
    calculateButton = tk.Button(New_Window, text = 'calculate')
    calculateButton.place(x=250,y=250)
    for x in range(len(fooditems)):
        if Checkbutton.get(x) == 1:
            fooditems2.append[x]
    fooditems2.grid(column=0, row=x)
    combobox.grid(column=15, row=x)
    New_Window.mainloop()


for x in range(len(fooditems)):
    a = Checkbutton(menu, text="", variable=fooditems[x], onvalue = 1, offvalue = 0)
    b = Label(menu, text=fooditems[x])
    a.grid(column=0, row=x)
    b.grid(column=5, row=x)
    
    

confirmButton = tk.Button(menu, text = 'Confirm', command=Open)
confirmButton.place(x=250,y=250)

menu.mainloop()
Reply


Messages In This Thread
tkinter checkbutton if checked - by MC2020 - Jan-20-2020, 05:45 PM
RE: tkinter checkbutton if checked - by woooee - Jan-20-2020, 10:00 PM
RE: tkinter checkbutton if checked - by joe_momma - Jan-21-2020, 07:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [closed] "checked" variable (attribute?) origin? paul18fr 4 2,488 Mar-05-2024, 04:20 PM
Last Post: deanhystad
  Checkbutton writing selection to file blakefindlay 1 2,806 Jan-28-2021, 01:56 PM
Last Post: deanhystad
Question [Tkinter] Checkbutton clicks events does not update visually. nicolaask 1 4,422 Dec-20-2020, 06:11 PM
Last Post: nicolaask
  [Tkinter] How to insert 'Checkbutton' to 'Treeview' and associate each item? water 2 16,540 Dec-19-2020, 05:24 PM
Last Post: water
  Find Checkbutton State PEGylated_User 3 4,347 Oct-23-2020, 12:43 AM
Last Post: Larz60+
  [tkinter] not getting checkbutton value when clicked OogieM 5 11,133 Sep-20-2020, 04:49 PM
Last Post: deanhystad
  [Tkinter] ttk.Checkbutton set on/off ifigazsi 5 15,859 Apr-04-2020, 07:34 PM
Last Post: deanhystad
  [Tkinter] Can't seem to get the current state of a checkbutton. p_hobbs 6 4,690 Nov-07-2019, 11:38 PM
Last Post: p_hobbs
  [Tkinter] Create a set of checkbutton widgets and refer to every one of them individually? Mariano 1 3,401 Apr-11-2019, 06:20 PM
Last Post: woooee
  [Tkinter] Completing Action when CheckBox is Checked Anysja 2 9,774 Aug-02-2018, 04:38 PM
Last Post: Anysja

Forum Jump:

User Panel Messages

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