DrGenius
DrGenius

Reputation: 967

Tkinter store choices- values inside variables

I am trying to play and learn with tkinter :

import tkinter as tk
from tkinter import *
from tkcalendar import Calendar, DateEntry

gui = Tk(className='STUDENTS')
gui.geometry("500x300")


def openNewWindow2():
    newWindow1 = Toplevel(gui)
    newWindow1.title("STUDENTS")
    newWindow1.geometry("500x300")
    Label(newWindow1, text='Select How many students?').pack()
    options2 = [
        "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
    ]
    clicked = StringVar()
    clicked.set("1")
    drop = OptionMenu(newWindow1, clicked, *options2)
    drop.pack()
    btn5 = Button(newWindow1,
                  text="GENERATE!!!",
                  command"#some function to use the values of dropdown and maxcal#")
    btn5.pack(pady=20)
    maxcal = DateEntry(newWindow1, width=12, background='darkblue',
                foreground='white', borderwidth=2)
    maxcal.pack(padx=10, pady=10)

label = Label(gui, text='test1~')
label.pack(pady=10)
btn2 = Button(gui,
              text="generator",
              command=openNewWindow2)

btn2.pack(pady=20)
gui.mainloop()

This will create a window with a dropdown menu. I want to hit the btn5 and store the values of the dropdown menu and the calendar in another window after. Is this possible?

Upvotes: 0

Views: 72

Answers (1)

Delrius Euphoria
Delrius Euphoria

Reputation: 15098

This is pretty simple, something like this should work:

def openNewWindow2():
    newWindow1 = Toplevel(gui)
    def func():
        print('hello world'*int(clicked.get()))

    ....
    btn5 = Button(newWindow1,text="GENERATE!!!",command=func)

It is something special with python that I don't think any other programing languages offer. You can multiply a string(I guess all iterables) with an integer to repeat it that many times.

Upvotes: 1

Related Questions