在所有选项卡上显示菜单 Tkinter

Display menu on all Tabs Tkinter

提问人:learningToCode 提问时间:11/15/2023 更新时间:11/15/2023 访问量:18

问:

我已经创建了我的选项卡,但我正在尝试放置一个对所有选项卡可见/使用的菜单。 我创建了包含新游戏和退出的菜单,但它不会为我显示。有人可以告诉我哪里出了问题吗?

我尝试将菜单放在我的根目录和选项卡上,但使用这两种方法都不会显示给我。

from tkinter import *
from tkinter import ttk, messagebox
import random
from PIL import ImageTk, Image

game = Tk()
game.title('Memory Game Challenge')
game.geometry("1100x1900")

# Images
base = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/white.jpeg").resize((125, 125)))
img1 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_1.png").resize((125, 125)))
img2 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_2.png").resize((125, 125)))
img3 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_3.png").resize((125, 125)))
img4 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_4.png").resize((125, 125)))
img5 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_5.png").resize((125, 125)))
img6 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_6.png").resize((125, 125)))
img7 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_7.png").resize((125, 125)))
img8 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_8.png").resize((125, 125)))
img9 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_9.png").resize((125, 125)))
img10 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/red_10.png").resize((125, 125)))
img11 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_1.png").resize((125, 125)))
img12 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_2.png").resize((125, 125)))
img13 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_3.png").resize((125, 125)))
img14 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_4.png").resize((125, 125)))
img15 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_5.png").resize((125, 125)))
img16 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_6.png").resize((125, 125)))
img17 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_7.png").resize((125, 125)))
img18 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_8.png").resize((125, 125)))
img19 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_9.png").resize((125, 125)))
img20 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/brown_10.png").resize((125, 125)))
img21 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_1.png").resize((125, 125)))
img22 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_2.jpeg").resize((125, 125)))
img23 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_3.png").resize((125, 125)))
img24 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_4.jpeg").resize((125, 125)))
img25 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_5.png").resize((125, 125)))
img26 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_6.png").resize((125, 125)))
img27 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_7.png").resize((125, 125)))
img28 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_8.png").resize((125, 125)))
img29 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_9.png").resize((125, 125)))
img30 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/yellow_10.png").resize((125, 125)))
img31 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_1.png").resize((125, 125)))
img32 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_2.png").resize((125, 125)))
img33 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_3.png").resize((125, 125)))
img34 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_4.png").resize((125, 125)))
img35 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_5.jpeg").resize((125, 125)))
img36 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_6.png").resize((125, 125)))
img37 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_7.jpeg").resize((125, 125)))
img38 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_8.png").resize((125, 125)))
img39 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_9.jpeg").resize((125, 125)))
img40 = ImageTk.PhotoImage(Image.open("/Users/amywilson/PycharmProjects/Images/green_10.png").resize((125, 125)))

# Create Frames for the Level Tabs
tabs = ttk.Notebook(game)

# Create Easy Frame 4 * 4
easy_frame = ttk.Frame(tabs)
easy_frame.pack(fill="both", expand=TRUE)

# Create Medium Frame 6 * 6
medium_frame = ttk.Frame(tabs)
medium_frame.pack(fill="both", expand=TRUE)

# Create Hard Frame 8 * 8
hard_frame = ttk.Frame(tabs)
hard_frame.pack(fill="both", expand=TRUE)

tabs.add(easy_frame, text='Easy')
tabs.add(medium_frame, text='Medium')
tabs.add(hard_frame, text='Hard')
tabs.pack(pady=10, expand=TRUE)

# Make a counter variable to do winning message
global winner1, winner2, winner3
winner1 = 0
winner2 = 0
winner3 = 0

# -----------Creating the Easy Level------------------
# Creating list for matches for Easy
matches = [img1, img1, img2, img2, img3, img3, img4, img4, img5, img5, img6, img6, img7, img7, img8, img8]

# Shuffle matches
random.shuffle(matches)

# Define Variables for Easy
count = 0
answer_list = []
answer_dictionary = {}


# Define function for creating a new game
def newGame():
    global matches, matches2, matches3, winner1, winner2, winner3
    if tabs.index("current") == 0:
        matches = [img1, img1, img2, img2, img3, img3, img4, img4, img5, img5, img6, img6, img7, img7, img8, img8]
        random.shuffle(matches)
        match_label.config(text=" ")
        buttonList = [b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15]
        for button in buttonList:
            button.config(image=base, state="normal")
    elif tabs.index("current") == 1:
        matches2 = [img1, img1, img2, img2, img3, img3, img4, img4, img5, img5, img6, img6, img7, img7, img8, img8,
                    img9, img9, img10, img10, img11, img11, img12, img12, img13, img13, img14, img14, img15, img15,
                    img16, img16, img17, img17, img18, img18]
        random.shuffle(matches2)
        match_label.config(text=" ")
        buttonList2 = [b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34,
                       b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51]
        for button in buttonList2:
            button.config2(image=base, state="normal")
    else:
        matches3 = [img1, img1, img2, img2, img3, img3, img4, img4, img5, img5, img6, img6, img7, img7, img8, img8,
                    img9, img9, img10, img10, img11, img11, img12, img12, img13, img13, img14, img14, img15, img15,
                    img16, img16, img17, img17, img18, img18, img19, img19, img20, img20, img21, img21, img22, img22,
                    img23, img23, img24, img24, img25, img25, img26, img26, img27, img27, img28, img28, img29, img29,
                    img30, img30, img31, img31, img32, img32]
        random.shuffle(matches3)
        match_label3.config(text=" ")
        buttonList3 = [b52, b53, b54, b55, b56, b57, b58, b59, b60, b61, b62, b63, b64, b65, b66, b67, b68, b69, b70,
                       b71, b72, b73, b74, b75, b76, b77, b78, b79, b80, b81, b82, b83, b84, b85, b86, b87, b88, b89,
                       b90, b91, b92, b93, b94, b95, b96, b97, b98, b99, b100, b101, b102, b103, b104, b105, b106, b107,
                       b108, b109, b110, b111, b112, b113, b114, b115]
        for button in buttonList3:
            button.config(image=base, state="normal")


# Define function for winning the game
def win():
    game.update()
    game.after(800)
    messagebox.showinfo("Winner", "Congratulations, You Won!!")


# Define function for clicking the button
def button_click(b, number):
    global count, answer_list, answer_dictionary, winner1

    if b["image"] == str(base) and count < 2 and (tabs.index("current") == 0):
        b["image"] = matches[number]
        # adding the number to answer list
        answer_list.append(number)
        # Adding number and button to answer dictionary
        answer_dictionary[b] = matches[number]
        # Increment count
        count += 1

    # Determine if they match
    if len(answer_list) == 2:
        if matches[answer_list[0]] == matches[answer_list[1]]:
            match_label.config(text="You Found a Match")
            for key in answer_dictionary:
                key["state"] = "disable"
            count = 0
            answer_list = []
            answer_dictionary = {}
            winner1 += 1
            if winner1 == 8:
                win()
        else:
            match_label.config(text="Try again")
            # force update and pause so player can see second card
            game.update()
            game.after(2000)
            count = 0
            answer_list = []

            # Reset buttons to be blank
            for key in answer_dictionary:
                key["image"] = base

            answer_dictionary = {}


# Create Buttons for Easy layout
b0 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b0, 0))
b1 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b1, 1))
b2 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b2, 2))
b3 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b3, 3))
b4 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b4, 4))
b5 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b5, 5))
b6 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b6, 6))
b7 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b7, 7))
b8 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b8, 8))
b9 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b9, 9))
b10 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b10, 10))
b11 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b11, 11))
b12 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b12, 12))
b13 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b13, 13))
b14 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b14, 14))
b15 = Button(easy_frame, image=base, height=125, width=125, command=lambda: button_click(b15, 15))

# Assign buttons to Grid
b0.grid(row=0, column=0)
b1.grid(row=0, column=1)
b2.grid(row=0, column=2)
b3.grid(row=0, column=3)

b4.grid(row=1, column=0)
b5.grid(row=1, column=1)
b6.grid(row=1, column=2)
b7.grid(row=1, column=3)

b8.grid(row=2, column=0)
b9.grid(row=2, column=1)
b10.grid(row=2, column=2)
b11.grid(row=2, column=3)

b12.grid(row=3, column=0)
b13.grid(row=3, column=1)
b14.grid(row=3, column=2)
b15.grid(row=3, column=3)

match_label = Label(game, text="")
match_label.pack(pady=5)

# ------------Creating the Medium Level---------------
# Creating list for matches for Medium
matches2 = [img1, img1, img2, img2, img3, img3, img4, img4, img5, img5, img6, img6, img7, img7, img8, img8, img9, img9,
            img10, img10, img11, img11, img12, img12, img13, img13, img14, img14, img15, img15, img16, img16, img17,
            img17, img18, img18]

# Shuffle matches
random.shuffle(matches2)

# Define Variables for Medium
count2 = 0
answer_list2 = []
answer_dictionary2 = {}


# Define function for clicking the button
def button_click2(b, number):
    global count2, answer_list2, answer_dictionary2, winner2
    if b["image"] == str(base) and count2 < 2 and (tabs.index("current") == 1):
        b["image"] = matches2[number]
        # adding the number to answer list
        answer_list2.append(number)
        # Adding number and button to answer dictionary
        answer_dictionary2[b] = matches2[number]
        # Increment count
        count2 += 1

    # Determine if they match
    if len(answer_list2) == 2:
        if matches2[answer_list2[0]] == matches2[answer_list2[1]]:
            match_label2.config(text="You Found a Match")
            for key in answer_dictionary2:
                key["state"] = "disable"
            count2 = 0
            answer_list2 = []
            answer_dictionary2 = {}
            winner2 += 1
            if winner2 == 18:
                win()
        else:
            match_label2.config(text="Try again")
            # force update and pause so player can see second card
            game.update()
            game.after(1000)
            count2 = 0
            answer_list2 = []

            # Reset buttons to be blank
            for key in answer_dictionary2:
                key["image"] = base

            answer_dictionary2 = {}


# Create button for Medium Layout
b16 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b16, 0))
b17 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b17, 1))
b18 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b18, 2))
b19 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b19, 3))
b20 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b20, 4))
b21 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b21, 5))
b22 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b22, 6))
b23 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b23, 7))
b24 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b24, 8))
b25 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b25, 9))
b26 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b26, 10))
b27 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b27, 11))
b28 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b28, 12))
b29 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b29, 13))
b30 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b30, 14))
b31 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b31, 15))
b32 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b32, 16))
b33 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b33, 17))
b34 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b34, 18))
b35 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b35, 19))
b36 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b36, 20))
b37 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b37, 21))
b38 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b38, 22))
b39 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b39, 23))
b40 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b40, 24))
b41 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b41, 25))
b42 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b42, 26))
b43 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b43, 27))
b44 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b44, 28))
b45 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b45, 29))
b46 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b46, 30))
b47 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b47, 31))
b48 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b48, 32))
b49 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b49, 33))
b50 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b50, 34))
b51 = Button(medium_frame, image=base, height=125, width=125, command=lambda: button_click2(b51, 35))

# Assign buttons to Grid Medium
b16.grid(row=0, column=0)
b17.grid(row=0, column=1)
b18.grid(row=0, column=2)
b19.grid(row=0, column=3)
b20.grid(row=0, column=4)
b21.grid(row=0, column=5)

b22.grid(row=1, column=0)
b23.grid(row=1, column=1)
b24.grid(row=1, column=2)
b25.grid(row=1, column=3)
b26.grid(row=1, column=4)
b27.grid(row=1, column=5)

b28.grid(row=2, column=0)
b29.grid(row=2, column=1)
b30.grid(row=2, column=2)
b31.grid(row=2, column=3)
b32.grid(row=2, column=4)
b33.grid(row=2, column=5)

b34.grid(row=3, column=0)
b35.grid(row=3, column=1)
b36.grid(row=3, column=2)
b37.grid(row=3, column=3)
b38.grid(row=3, column=4)
b39.grid(row=3, column=5)

b40.grid(row=4, column=0)
b41.grid(row=4, column=1)
b42.grid(row=4, column=2)
b43.grid(row=4, column=3)
b44.grid(row=4, column=4)
b45.grid(row=4, column=5)

b46.grid(row=5, column=0)
b47.grid(row=5, column=1)
b48.grid(row=5, column=2)
b49.grid(row=5, column=3)
b50.grid(row=5, column=4)
b51.grid(row=5, column=5)

match_label2 = Label(game, text="")
match_label2.pack(pady=5)

# ------------Creating the Hard Level---------------

# Creating list for matches for Medium
matches3 = [img1, img1, img2, img2, img3, img3, img4, img4, img5, img5, img6, img6, img7, img7, img8, img8, img9, img9,
            img10, img10, img11, img11, img12, img12, img13, img13, img14, img14, img15, img15, img16, img16, img17,
            img17, img18, img18, img19, img19, img20, img20, img21, img21, img22, img22, img23, img23, img24, img24,
            img25, img25, img26, img26, img27, img27, img28, img28, img29, img29, img30, img30, img31, img31, img32,
            img32]

# Shuffle matches
random.shuffle(matches3)

# Define Variables for Medium Level
count3 = 0
answer_list3 = []
answer_dictionary3 = {}


# Define function for clicking the button (flip card)
def button_click3(b, number):
    global count3, answer_list3, answer_dictionary3, winner3
    if b["image"] == str(base) and count2 < 2 and (tabs.index("current") == 2):
        b["image"] = matches3[number]
        # adding the number to answer list
        answer_list3.append(number)
        # Adding number and button to answer dictionary
        answer_dictionary3[b] = matches3[number]
        # Increment count
        count3 += 1

    # Determine if they match
    if len(answer_list3) == 2:
        if matches3[answer_list3[0]] == matches3[answer_list3[1]]:
            match_label3.config(text="You Found a Match")
            for key in answer_dictionary3:
                key["state"] = "disable"
            count3 = 0
            answer_list3 = []
            answer_dictionary3 = {}
            winner3 += 1
            if winner3 == 32:
                win()
        else:
            match_label3.config(text="Try again")
            # force update and pause so player can see second card
            game.update()
            game.after(800)
            count3 = 0
            answer_list3 = []

            # Reset buttons to be blank
            for key in answer_dictionary3:
                key["image"] = base

            answer_dictionary3 = {}


# Creating Button for Hard layout
b52 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b52, 0))
b53 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b53, 1))
b54 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b54, 2))
b55 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b55, 3))
b56 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b56, 4))
b57 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b57, 5))
b58 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b58, 6))
b59 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b59, 7))
b60 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b60, 8))
b61 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b61, 9))
b62 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b62, 10))
b63 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b63, 11))
b64 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b64, 12))
b65 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b65, 13))
b66 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b66, 14))
b67 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b67, 15))
b68 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b68, 16))
b69 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b69, 17))
b70 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b70, 18))
b71 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b71, 19))
b72 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b72, 20))
b73 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b73, 21))
b74 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b74, 22))
b75 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b75, 23))
b76 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b76, 24))
b77 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b77, 25))
b78 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b78, 26))
b79 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b79, 27))
b80 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b80, 28))
b81 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b81, 29))
b82 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b82, 30))
b83 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b83, 31))
b84 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b84, 32))
b85 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b85, 33))
b86 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b86, 34))
b87 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b87, 35))
b88 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b88, 36))
b89 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b89, 37))
b90 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b90, 38))
b91 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b91, 39))
b92 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b92, 40))
b93 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b93, 41))
b94 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b94, 42))
b95 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b95, 43))
b96 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b96, 44))
b97 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b97, 45))
b98 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b98, 46))
b99 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b99, 47))
b100 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b100, 48))
b101 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b101, 49))
b102 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b102, 50))
b103 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b103, 51))
b104 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b104, 52))
b105 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b105, 53))
b106 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b106, 54))
b107 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b107, 55))
b108 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b108, 56))
b109 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b109, 57))
b110 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b110, 58))
b111 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b111, 59))
b112 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b112, 60))
b113 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b113, 61))
b114 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b114, 62))
b115 = Button(hard_frame, image=base, height=125, width=125, command=lambda: button_click3(b115, 63))

# Assign buttons to grid Hard
b52.grid(row=1, column=0)
b53.grid(row=1, column=1)
b54.grid(row=1, column=2)
b55.grid(row=1, column=3)
b56.grid(row=1, column=4)
b57.grid(row=1, column=5)
b58.grid(row=1, column=6)
b59.grid(row=1, column=7)

b60.grid(row=2, column=0)
b61.grid(row=2, column=1)
b62.grid(row=2, column=2)
b63.grid(row=2, column=3)
b64.grid(row=2, column=4)
b65.grid(row=2, column=5)
b66.grid(row=2, column=6)
b67.grid(row=2, column=7)

b68.grid(row=3, column=0)
b69.grid(row=3, column=1)
b70.grid(row=3, column=2)
b71.grid(row=3, column=3)
b72.grid(row=3, column=4)
b73.grid(row=3, column=5)
b74.grid(row=3, column=6)
b75.grid(row=3, column=7)

b76.grid(row=4, column=0)
b77.grid(row=4, column=1)
b78.grid(row=4, column=2)
b79.grid(row=4, column=3)
b80.grid(row=4, column=4)
b81.grid(row=4, column=5)
b82.grid(row=4, column=6)
b83.grid(row=4, column=7)

b84.grid(row=5, column=0)
b85.grid(row=5, column=1)
b86.grid(row=5, column=2)
b87.grid(row=5, column=3)
b88.grid(row=5, column=4)
b89.grid(row=5, column=5)
b90.grid(row=5, column=6)
b91.grid(row=5, column=7)

b92.grid(row=6, column=0)
b93.grid(row=6, column=1)
b94.grid(row=6, column=2)
b95.grid(row=6, column=3)
b96.grid(row=6, column=4)
b97.grid(row=6, column=5)
b98.grid(row=6, column=6)
b99.grid(row=6, column=7)

b100.grid(row=7, column=0)
b101.grid(row=7, column=1)
b102.grid(row=7, column=2)
b103.grid(row=7, column=3)
b104.grid(row=7, column=4)
b105.grid(row=7, column=5)
b106.grid(row=7, column=6)
b107.grid(row=7, column=7)

b108.grid(row=8, column=0)
b109.grid(row=8, column=1)
b110.grid(row=8, column=2)
b111.grid(row=8, column=3)
b112.grid(row=8, column=4)
b113.grid(row=8, column=5)
b114.grid(row=8, column=6)
b115.grid(row=8, column=7)

match_label3 = Label(game, text="")
match_label3.pack(pady=5)

# Create Options menu
menuBar = Menu(tabs)
option = Menu(menuBar, tearoff=0, fg="black")
option.add_command(label="New Game", command=newGame)
option.add_command(label="Exit Game", command=game.quit)
menuBar.add_cascade(label="Options", menu=option)
game.config(menu=menuBar)

game.mainloop()
Python tkinter 选项卡

评论


答: 暂无答案