It's a Python question.

Asked 2 years ago, Updated 2 years ago, 96 views

from tkinter import *
import matplotlib.pyplot as plt

win = Tk()

win.geometry("1024x576")
win.title("Minecraft bukkit")
win.option_add("*Font", "NotoSansKR-Medium 20")

ent = Entry(win)
ent.insert (0"Enter server to find")
def clear(event):
    ifent.get() == "Enter the server to find":
        ent.delete(0,len(ent.get()))
ent.bind("<Button-1>", clear)
ent.pack(side = "top")
ent.pack(pady = 50)

SERVER_BUTTONS = 0
CREATING_SERVER = 0
for SERVER_BUTTONS in range(0, CREATING_SERVER, 1):
    slot_SERVER_BUTTONS = Button(win)






"""btn = Button(win)
btn.config (text = "Add Server")
btn.pack(side = "bottom")
btn.pack(pady = 5)
btn['bg'] = "#9bba86"
Button()"""

win.mainloop()

It's the whole code I used to make. Double

SERVER_BUTTONS = 0
CREATING_SERVER = 0
for SERVER_BUTTONS in range(0, CREATING_SERVER, 1):
    slot_SERVER_BUTTONS = Button(win)

Question about this code. I want to create a slot function every time I click on the for door button When SERVER_BUTTONS = 1, it would be nice if a variable was made with slot_1.

tkinter for python

2022-09-20 20:02

1 Answers

I understand that there is no way to create a variable in the for statement As an alternative, I use a method of generating a variable name as a key value in dictionary, which can be used as a variable in the form of a dictionary name [key] I hope it helps youYo

CREATING_SERVER = 12
SERVER_dict = dict()
for SERVER_BUTTONS in range(0, CREATING_SERVER, 1):
    SERVER_dict[f'slot_{SERVER_BUTTONS}'] = 1


2022-09-20 20:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.