|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- from tkinter import *
- from math import *
- from time import *
- food = ['LV4 苹果(48)', 'LV4 苹果(48)', 'LV4 苹果(48)']
- power = ['LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺']
- full = 500
- money = 666
- root = Tk()
- root.title('六六湖秘密探险 V2.0 Feb.6th 2024 -- 六六游戏城V8888.66.5.1.0.456.17.0a7')
- w = Canvas(root, width=550, height=350)
- w.pack()
- v = IntVar()
- v.set(1)
- now = '家'
- road = {'家':{'鱼C公园':[1, 2, 30], '食物超市1~6':[2, 4, 90]}, \
- '鱼C公园':{'家':[1, 2, 30], '食物超市1~6':[2, 3, 48], '武器超市1~6':[1, 3, 36]}, \
- '食物超市1~6':{'家':[2, 4, 90], '鱼C公园':[2, 3, 48], 'LV1打工仔公司':[3, 4, 100]}, \
- '武器超市1~6':{'鱼C公园':[1, 3, 36], 'LV1打工仔公司':[6, 6, 54]}, \
- 'LV1打工仔公司':{'食物超市1~6':[3, 4, 100], '武器超市1~6':[6, 6, 54]}}
- def callback():
- print('啊!我被调用了')
- def go2(button):
- if button == now:
- label3 = Label(w, text='你就在这儿')
- label3_window = Canvas.create_window(w, 540, 200, window=label3)
- else:
- w.delete(ALL)
- sleep(0.5)
- label4 = Label(w, text='Loading... 口口20%')
- label4_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
- w.delete(ALL)
- sleep(0.5)
- label5 = Label(w, text='Loading... 口口口口40%')
- label5_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
- w.delete(ALL)
- sleep(0.5)
- label6 = Label(w, text='【777警报】怪兽来袭!')
- label6_window = Canvas.create_window(w, 275, 340, window=label4)
- lpower = len(power)
- for i in range(lpower):
- Radiobutton(v, text=power[i], variable=v, value=i+1, indicatoron=False).pack(anchor=W)
- position = {'A':((5, 5), (65, 65), 30, 'red', '家'), \
- 'B':((70, 70), (130, 130), 30, 'orange', '鱼C公\n园'), \
- 'C':((170, 70), (230, 130), 30, 'yellow', '食物超\n市1~6'), \
- 'D':((70, 170), (130, 230), 30, 'green', '武器超\n市1~6'), \
- 'E':((170, 270), (230, 330), 30, 'blue', 'LV1打\n工仔公\n司')}
- def connect(x):
- a = position[x[0]]
- b = position[x[1]]
- a_center = ((a[0][0] + a[2]), (a[0][1] + a[2]))
- b_center = ((b[0][0] + b[2]), (b[0][1] + b[2]))
- if a_center[0] < b_center[0] and a_center[1] < b_center[1]:
- #右下I
- temp = (a_center[0], b_center[1])
- s1 = b_center[0] - temp[0]
- s2 = temp[1] - a_center[1]
- diff1 = 30 * sin(atan(s1/s2))
- diff2 = 30 * sin(atan(s2/s1))
- return a_center[0] + diff1, a_center[1] + diff2, b_center[0] - diff1, b_center[1] - diff2
- elif a_center[0] > b_center[0] and a_center[1] < b_center[1]:
- #左下II
- temp = (a_center[0], b_center[1])
- s1 = temp[1] - b_center[1]
- s2 = temp[0] - a_center[0]
- diff1 = 30 * sin(atan(s1/s2))
- diff2 = 30 * sin(atan(s2/s1))
- return a_center[0] - diff1, a_center[1] + diff2, b_center[0] + diff1, b_center[1] - diff2
- elif a_center[0] > b_center[0] and a_center[1] > b_center[1]:
- #左上III
- temp = (a_center[0], b_center[1])
- s1 = temp[1] - b_center[1]
- s2 = a_center[0] - temp[0]
- diff1 = 30 * sin(atan(s1/s2))
- diff2 = 30 * sin(atan(s2/s1))
- return a_center[0] - diff1, a_center[1] - diff2, b_center[0] + diff1, b_center[1] + diff2
- elif a_center[0] < b_center[0] and a_center[1] > b_center[1]:
- #右上IV
- temp = (a_center[0], b_center[1])
- s1 = temp[1] - b_center[1]
- s2 = temp[0] - a_center[0]
- diff1 = 30 * sin(atan(s1/s2))
- diff2 = 30 * sin(atan(s2/s1))
- return a_center[0] + diff1, a_center[1] - diff2, b_center[0] - diff1, b_center[1] + diff2
- elif a_center[1] == b_center[1]:
- #同行
- return a_center[0] + 30, a_center[1], b_center[0] - 30, b_center[1]
- elif a_center[0] == b_center[0]:
- #同列
- return a_center[0], a_center[1] + 30, b_center[0], b_center[1] - 30
- def go():
- w.delete(ALL)
- for i in list(position.keys()):
- w.create_oval(position[i][0][0], position[i][0][1], position[i][1][0], position[i][1][1], fill=position[i][3])
- center = (position[i][0][0] + position[i][2], position[i][0][1] + position[i][2])
- w.create_text(center[0], center[1], text=position[i][4])
- myline = [('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D'), ('C', 'E'), ('D', 'E')]
- for each in myline:
- w.create_line(connect(each))
- the_label = Label(w, text='你想去哪儿?')
- the_label_window = Canvas.create_window(w, 540, 10, anchor=E, window=the_label)
- button_a = Button(w, text='家', command=go2('家'))
- button_a_window = Canvas.create_window(w, 540, 35, anchor=E, window=button_a)
- button_b = Button(w, text='鱼C公园', command=go2('鱼C公园'))
- button_b_window = Canvas.create_window(w, 540, 60, anchor=E, wind3ow=button_b)
- button_c = Button(w, text='食物超市1~6', command=go2('食物超市1~6'))
- button_c_window = Canvas.create_window(w, 540, 85, anchor=E, window=button_c)
- button_d = Button(w, text='武器超市1~6', command=go2('武器超市1~6'))
- button_d_window = Canvas.create_window(w, 540, 110, anchor=E, window=button_d)
- button_e = Button(w, text='LV1打工仔公司', command=go2('LV1打工仔公司'))
- button_e_window = Canvas.create_window(w, 540, 135, anchor=E, window=button_e)
- label1 = Label(w, text='六六湖秘密探险 V2.0\nSixty-six Lake Secret Adventure')
- label1_window = Canvas.create_window(w, 275, 125, window=label1)
- label2 = Label(w, text='你要做什么?')
- label2_window = Canvas.create_window(w, 275, 150, window=label2)
- choose1 = Button(w, text='出发', command=go)
- choose1_window = Canvas.create_window(w, 275, 175, window=choose1)
- choose2 = Button(w, text='查看背包', command=callback)
- choose1_window = Canvas.create_window(w, 275, 200, window=choose2)
- mainloop()
复制代码- Exception in Tkinter callback
- Traceback (most recent call last):
- File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/tkinter/__init__.py", line 2043, in __call__
- return self.func(*args)
- ~~~~~~~~~^^^^^^^
- File "/Users/zhangxiang/Documents/六六湖秘密探险2.x(最新).py", line 117, in go
- button_b = Button(w, text='鱼C公园', command=go2('鱼C公园'))
- ~~~^^^^^^^^^^^
- File "/Users/zhangxiang/Documents/六六湖秘密探险2.x(最新).py", line 49, in go2
- Radiobutton(v, text=power[i], variable=v, value=i+1, indicatoron=False).pack(anchor=W)
- ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/tkinter/__init__.py", line 3585, in __init__
- Widget.__init__(self, master, 'radiobutton', cnf, kw)
- ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/tkinter/__init__.py", line 2718, in __init__
- self._setup(master, cnf)
- ~~~~~~~~~~~^^^^^^^^^^^^^
- File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/tkinter/__init__.py", line 2687, in _setup
- self.tk = master.tk
- ^^^^^^^^^
- AttributeError: 'IntVar' object has no attribute 'tk'. Did you mean: '_tk'?
复制代码
修正了你程序的部分问题,具体我懒得介绍了,自己看吧,求一个最佳答案。
- from tkinter import *
- from math import *
- from time import *
- food = ['LV4 苹果(48)', 'LV4 苹果(48)', 'LV4 苹果(48)']
- power = ['LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺']
- full = 500
- money = 666
- root = Tk()
- root.title('六六湖秘密探险 V2.0 Feb.6th 2024 -- 六六游戏城V8888.66.5.1.0.456.17.0a7')
- w = Canvas(root, width=550, height=350)
- w.pack()
- v = IntVar()
- v.set(1)
- now = '家'
- road = {'家':{'鱼C公园':[1, 2, 30], '食物超市1~6':[2, 4, 90]}, \
- '鱼C公园':{'家':[1, 2, 30], '食物超市1~6':[2, 3, 48], '武器超市1~6':[1, 3, 36]}, \
- '食物超市1~6':{'家':[2, 4, 90], '鱼C公园':[2, 3, 48], 'LV1打工仔公司':[3, 4, 100]}, \
- '武器超市1~6':{'鱼C公园':[1, 3, 36], 'LV1打工仔公司':[6, 6, 54]}, \
- 'LV1打工仔公司':{'食物超市1~6':[3, 4, 100], '武器超市1~6':[6, 6, 54]}}
- def callback():
- print('啊!我被调用了')
- def go2(button):
- if button == now:
- label3 = Label(w, text='你就在这儿')
- label3_window = Canvas.create_window(w, 540, 200, window=label3)
- else:
- w.delete(ALL)
- w.after(500)
- label4 = Label(w, text='Loading... 口口20%')
- label4_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
- w.delete(ALL)
- w.after(500)
- label5 = Label(w, text='Loading... 口口口口40%')
- label5_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
- w.delete(ALL)
- w.after(500)
- label6 = Label(w, text='【777警报】怪兽来袭!')
- label6_window = Canvas.create_window(w, 275, 340, window=label4)
- lpower = len(power)
- for i in range(lpower):
- Radiobutton(w, text=power[i], variable=v, value=i+1, indicatoron=False).pack(anchor=W)
- position = {'A':((5, 5), (65, 65), 30, 'red', '家'), \
- 'B':((70, 70), (130, 130), 30, 'orange', '鱼C公\n园'), \
- 'C':((170, 70), (230, 130), 30, 'yellow', '食物超\n市1~6'), \
- 'D':((70, 170), (130, 230), 30, 'green', '武器超\n市1~6'), \
- 'E':((170, 270), (230, 330), 30, 'blue', 'LV1打\n工仔公\n司')}
- def connect(x):
- a = position[x[0]]
- b = position[x[1]]
- a_center = ((a[0][0] + a[2]), (a[0][1] + a[2]))
- b_center = ((b[0][0] + b[2]), (b[0][1] + b[2]))
- if a_center[0] < b_center[0] and a_center[1] < b_center[1]:
- #右下I
- temp = (a_center[0], b_center[1])
- s1 = b_center[0] - temp[0]
- s2 = temp[1] - a_center[1]
- diff1 = 30 * sin(atan(s1/s2))
- diff2 = 30 * sin(atan(s2/s1))
- return a_center[0] + diff1, a_center[1] + diff2, b_center[0] - diff1, b_center[1] - diff2
- elif a_center[0] > b_center[0] and a_center[1] < b_center[1]:
- #左下II
- temp = (a_center[0], b_center[1])
- s1 = temp[1] - b_center[1]
- s2 = temp[0] - a_center[0]
- diff1 = 30 * sin(atan(s1/s2))
- diff2 = 30 * sin(atan(s2/s1))
- return a_center[0] - diff1, a_center[1] + diff2, b_center[0] + diff1, b_center[1] - diff2
- elif a_center[0] > b_center[0] and a_center[1] > b_center[1]:
- #左上III
- temp = (a_center[0], b_center[1])
- s1 = temp[1] - b_center[1]
- s2 = a_center[0] - temp[0]
- diff1 = 30 * sin(atan(s1/s2))
- diff2 = 30 * sin(atan(s2/s1))
- return a_center[0] - diff1, a_center[1] - diff2, b_center[0] + diff1, b_center[1] + diff2
- elif a_center[0] < b_center[0] and a_center[1] > b_center[1]:
- #右上IV
- temp = (a_center[0], b_center[1])
- s1 = temp[1] - b_center[1]
- s2 = temp[0] - a_center[0]
- diff1 = 30 * sin(atan(s1/s2))
- diff2 = 30 * sin(atan(s2/s1))
- return a_center[0] + diff1, a_center[1] - diff2, b_center[0] - diff1, b_center[1] + diff2
- elif a_center[1] == b_center[1]:
- #同行
- return a_center[0] + 30, a_center[1], b_center[0] - 30, b_center[1]
- elif a_center[0] == b_center[0]:
- #同列
- return a_center[0], a_center[1] + 30, b_center[0], b_center[1] - 30
- def go():
- w.delete(ALL)
- for i in list(position.keys()):
- w.create_oval(position[i][0][0], position[i][0][1], position[i][1][0], position[i][1][1], fill=position[i][3])
- center = (position[i][0][0] + position[i][2], position[i][0][1] + position[i][2])
- w.create_text(center[0], center[1], text=position[i][4])
- myline = [('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D'), ('C', 'E'), ('D', 'E')]
- for each in myline:
- w.create_line(connect(each))
- the_label = Label(w, text='你想去哪儿?')
- the_label_window = Canvas.create_window(w, 540, 10, anchor=E, window=the_label)
- button_a = Button(w, text='家', command=lambda:go2('家'))
- button_a_window = Canvas.create_window(w, 540, 35, anchor=E, window=button_a)
- button_b = Button(w, text='鱼C公园', command=lambda:go2('鱼C公园'))
- button_b_window = Canvas.create_window(w, 540, 60, anchor=E, window=button_b)
- button_c = Button(w, text='食物超市1~6', command=lambda:go2('食物超市1~6'))
- button_c_window = Canvas.create_window(w, 540, 85, anchor=E, window=button_c)
- button_d = Button(w, text='武器超市1~6', command=lambda:go2('武器超市1~6'))
- button_d_window = Canvas.create_window(w, 540, 110, anchor=E, window=button_d)
- button_e = Button(w, text='LV1打工仔公司', command=lambda:go2('LV1打工仔公司'))
- button_e_window = Canvas.create_window(w, 540, 135, anchor=E, window=button_e)
- label1 = Label(w, text='六六湖秘密探险 V2.0\nSixty-six Lake Secret Adventure')
- label1_window = Canvas.create_window(w, 275, 125, window=label1)
- label2 = Label(w, text='你要做什么?')
- label2_window = Canvas.create_window(w, 275, 150, window=label2)
- choose1 = Button(w, text='出发', command=go)
- choose1_window = Canvas.create_window(w, 275, 175, window=choose1)
- choose2 = Button(w, text='查看背包', command=callback)
- choose1_window = Canvas.create_window(w, 275, 200, window=choose2)
- mainloop()
复制代码
|
|