Python Simple tkinter Program Question: Press button to switch to another screen

Asked 2 years ago, Updated 2 years ago, 50 views

I have about 5 coupons here and I'd like to make a coupon, would you like to use it? If I press cancel, I want to go back to the first screen, but I don't know what to do What should I do with that?

from tkinter import *

win = Tk()

win.geometry('1000x500')
win.title ("coupon user")
win.option_add("*Font", "50")

btn = Button (win, text = "Coupon1")    
btn2 = Button (win, text = 'Coupon2')   
btn3 = Button (win, text = 'Coupon3')
btn_1 = Button(win, text = 'Do you want to use it?')
btn_2 = Button (win, text = 'Do you want to cancel')


def alert():
    lab1 = Label(win)
    lab1.config(text = "10 coupons left.")
    lab1.pack()
    btn.destroy()
    btn2.destroy()
    btn3.destroy()
    btn_1.pack()
    btn_2.pack()


def alert2():
    text2 = Label (win, text = '2% of coupons left' % (10))
    text2.pack()
    btn.destroy()
    btn2.destroy()
    btn3.destroy()
    btn_1.pack()
    btn_2.pack()

def alert3():
    text3 = Label (win, text = '3% of coupons left' % (10))
    text3.pack()
    btn.destroy()
    btn2.destroy()
    btn3.destroy()
    btn_1.pack()
    btn_2.pack()

def alert5():
    btn_2.destroy()
    btn_1.destroy()  



btn.config(command = alert)
btn2.config(command = alert2)
btn3.config(command = alert3)
btn_1.config(command = alert4)
btn_2.config(command = alert5)


btn.pack()
btn2.pack()
btn3.pack()

tkinter python

2022-09-20 19:25

1 Answers

How about this?


2022-09-20 19:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.