मैंने एक फ्रेम बनाया और फिर कैनवास बनाया।
मैं कैनवास पर एक बटन जोड़ने के लिए आगे क्या करना चाहता हूं।
हालांकि, जब मैंने बटन पैक किया तो मैं कैनवास नहीं देख सकता!आप टिंकर कैनवास पर एक बटन कैसे बनाते हैं?
यहाँ मैं क्या करने की कोशिश की है:
from Tkinter import Tk, Canvas, Frame, Button
from Tkinter import BOTH, W, NW, SUNKEN, TOP, X, FLAT, LEFT
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Layout Test")
self.config(bg = '#F0F0F0')
self.pack(fill = BOTH, expand = 1)
#create canvas
canvas1 = Canvas(self, relief = FLAT, background = "#D2D2D2",
width = 180, height = 500)
canvas1.pack(side = TOP, anchor = NW, padx = 10, pady = 10)
#add quit button
button1 = Button(canvas1, text = "Quit", command = self.quit,
anchor = W)
button1.configure(width = 10, activebackground = "#33B5E5",
relief = FLAT)
button1.pack(side = TOP)
def main():
root = Tk()
root.geometry('800x600+10+50')
app = Example(root)
app.mainloop()
if __name__ == '__main__':
main()
धन्यवाद, यह बहुत उपयोगी है! – Tony