Tkinterでマップ選択画面にradiobuttonを配置して選んだマップのframeに飛べるシステムを作っています。しかしエラーが出てしまってうまく変数にradiobuttonのvalue値を組み込むことができません。
main.py
1# tkinterのインポート 2import tkinter as tk 3import tkinter.ttk as ttk 4import time 5import program as pg 6import talking as tg 7import keyboard 8import pygame 9 10if __name__ == "__main__": 11 #メインウィンドウの設定 12 root = tk.Tk() 13 root.attributes('-fullscreen', True) 14 root.bind('<Escape>', lambda e: root.destroy()) 15 root.geometry("1920x1200") 16 root.configure(bg='black') 17 root.grid_rowconfigure(0, weight=1) 18 root.grid_columnconfigure(0, weight=1) 19 20 #タイトルウィンドウ設置 21 frame = tk.Frame(root, bg='black') 22 frame.grid(row=0, column=0, sticky="nsew", pady=20) 23 24 #マップ画面 25 main_map = tk.Frame(root, bg='black') 26 main_map.grid(row=0, column=0, sticky="nsew", pady=20) 27 map_img = tk.PhotoImage(file='map.png') 28 map_img_label = tk.Label(main_map, image=map_img, background='black') 29 map_img_label.grid() 30 31 map_radio = tk.IntVar() 32 map_radio.set(0) 33 map_1 = tk.Radiobutton(map_img_label, value=0, variable=map_radio) 34 map_1.place(x=500, y=600) 35 map_2 = tk.Radiobutton(map_img_label, value=1, variable=map_radio) 36 map_2.place(x=1000, y=700) 37 map_3 = tk.Radiobutton(map_img_label, value=2, variable=map_radio) 38 map_3.place(x=1300, y=500) 39 map_select_button = tk.Button(main_map, text='選択', command=lambda:pg.change_map(map_radio)) 40 map_select_button.place(x=1800, y=1000) 41 42 #ろとの塔 43 roto = tk.Frame(root, bg='black') 44 roto.grid(row=0, column=0, sticky="nsew", pady=20) 45 talk_label = tk.Label(roto, text = tg.roto_tell[pg.roto_x]) 46 talk_label.place(x=0, y=800, width=1920, height=300) 47 48 #勇者の集落 49 yuusha = tk.Frame(root, bg='black') 50 yuusha.grid(row=0, column=0, sticky="nsew", pady=20) 51 talk_label = tk.Label(yuusha, text = tg.yuusha_tell[pg.yuusha_x]) 52 talk_label.place(x=0, y=800, width=1920, height=300) 53 54 #天空の洞窟 55 tenku = tk.Frame(root, bg='black') 56 tenku.grid(row=0, column=0, sticky="nsew", pady=20) 57 talk_label = tk.Label(tenku, text = tg.tenku_tell[pg.tenku_x]) 58 talk_label.place(x=0, y=800, width=1920, height=300) 59 60 # frameを前面にする 61 frame.tkraise() 62 63 root.mainloop()
program.py
1import talking as tg 2import time 3import tkinter as tk 4import tkinter.ttk as ttk 5import main 6import pygame 7 8map_no = [roto, yuusha, tenku] 9 10def change_map(var): 11 map_value= var.get() 12 map_no[map_value].tkraise()
error
1 map_no[map_value].tkraise() 2AttributeError: 'str' object has no attribute 'tkraise'
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/14 11:14
2022/04/14 11:25
2022/04/14 12:08
2022/04/14 12:47 編集
2022/04/14 12:38
2022/04/15 14:22
2022/04/16 04:20 編集