鱼C论坛

 找回密码
 立即注册
查看: 1353|回复: 7

[已解决]求助

[复制链接]
发表于 2024-2-9 17:42:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. from tkinter import *
  2. from math import *
  3. from time import *

  4. food = ['LV4 苹果(48)', 'LV4 苹果(48)', 'LV4 苹果(48)']
  5. power = ['LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺']
  6. full = 500
  7. money = 666

  8. root = Tk()
  9. root.title('六六湖秘密探险 V2.0 Feb.6th 2024 -- 六六游戏城V8888.66.5.1.0.456.17.0a7')

  10. w = Canvas(root, width=550, height=350)
  11. w.pack()

  12. v = IntVar()
  13. v.set(1)

  14. now = '家'

  15. road = {'家':{'鱼C公园':[1, 2, 30], '食物超市1~6':[2, 4, 90]}, \
  16.         '鱼C公园':{'家':[1, 2, 30], '食物超市1~6':[2, 3, 48], '武器超市1~6':[1, 3, 36]}, \
  17.         '食物超市1~6':{'家':[2, 4, 90], '鱼C公园':[2, 3, 48], 'LV1打工仔公司':[3, 4, 100]}, \
  18.         '武器超市1~6':{'鱼C公园':[1, 3, 36], 'LV1打工仔公司':[6, 6, 54]}, \
  19.         'LV1打工仔公司':{'食物超市1~6':[3, 4, 100], '武器超市1~6':[6, 6, 54]}}

  20. def callback():
  21.     print('啊!我被调用了')

  22. def go2(button):
  23.     if button == now:
  24.         label3 = Label(w, text='你就在这儿')
  25.         label3_window = Canvas.create_window(w, 540, 200, window=label3)
  26.     else:
  27.         w.delete(ALL)
  28.         sleep(0.5)
  29.         label4 = Label(w, text='Loading... 口口20%')
  30.         label4_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
  31.         w.delete(ALL)
  32.         sleep(0.5)
  33.         label5 = Label(w, text='Loading... 口口口口40%')
  34.         label5_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
  35.         w.delete(ALL)
  36.         sleep(0.5)
  37.         label6 = Label(w, text='【777警报】怪兽来袭!')
  38.         label6_window = Canvas.create_window(w, 275, 340, window=label4)
  39.         lpower = len(power)
  40.         for i in range(lpower):
  41.             Radiobutton(v, text=power[i], variable=v, value=i+1, indicatoron=False).pack(anchor=W)

  42. position = {'A':((5, 5), (65, 65), 30, 'red', '家'), \
  43.             'B':((70, 70), (130, 130), 30, 'orange', '鱼C公\n园'), \
  44.             'C':((170, 70), (230, 130), 30, 'yellow', '食物超\n市1~6'), \
  45.             'D':((70, 170), (130, 230), 30, 'green', '武器超\n市1~6'), \
  46.             'E':((170, 270), (230, 330), 30, 'blue', 'LV1打\n工仔公\n司')}

  47. def connect(x):
  48.     a = position[x[0]]
  49.     b = position[x[1]]
  50.     a_center = ((a[0][0] + a[2]), (a[0][1] + a[2]))
  51.     b_center = ((b[0][0] + b[2]), (b[0][1] + b[2]))
  52.     if a_center[0] < b_center[0] and a_center[1] < b_center[1]:
  53.         #右下I
  54.         temp = (a_center[0], b_center[1])
  55.         s1 = b_center[0] - temp[0]
  56.         s2 = temp[1] - a_center[1]
  57.         diff1 = 30 * sin(atan(s1/s2))
  58.         diff2 = 30 * sin(atan(s2/s1))
  59.         return a_center[0] + diff1, a_center[1] + diff2, b_center[0] - diff1, b_center[1] - diff2
  60.     elif a_center[0] > b_center[0] and a_center[1] < b_center[1]:
  61.         #左下II
  62.         temp = (a_center[0], b_center[1])
  63.         s1 = temp[1] - b_center[1]
  64.         s2 = temp[0] - a_center[0]
  65.         diff1 = 30 * sin(atan(s1/s2))
  66.         diff2 = 30 * sin(atan(s2/s1))
  67.         return a_center[0] - diff1, a_center[1] + diff2, b_center[0] + diff1, b_center[1] - diff2
  68.     elif a_center[0] > b_center[0] and a_center[1] > b_center[1]:
  69.         #左上III
  70.         temp = (a_center[0], b_center[1])
  71.         s1 = temp[1] - b_center[1]
  72.         s2 = a_center[0] - temp[0]
  73.         diff1 = 30 * sin(atan(s1/s2))
  74.         diff2 = 30 * sin(atan(s2/s1))
  75.         return a_center[0] - diff1, a_center[1] - diff2, b_center[0] + diff1, b_center[1] + diff2
  76.     elif a_center[0] < b_center[0] and a_center[1] > b_center[1]:
  77.         #右上IV
  78.         temp = (a_center[0], b_center[1])
  79.         s1 = temp[1] - b_center[1]
  80.         s2 = temp[0] - a_center[0]
  81.         diff1 = 30 * sin(atan(s1/s2))
  82.         diff2 = 30 * sin(atan(s2/s1))
  83.         return a_center[0] + diff1, a_center[1] - diff2, b_center[0] - diff1, b_center[1] + diff2
  84.     elif a_center[1] == b_center[1]:
  85.         #同行
  86.         return a_center[0] + 30, a_center[1], b_center[0] - 30, b_center[1]
  87.     elif a_center[0] == b_center[0]:
  88.         #同列
  89.         return a_center[0], a_center[1] + 30, b_center[0], b_center[1] - 30

  90. def go():
  91.     w.delete(ALL)
  92.     for i in list(position.keys()):
  93.         w.create_oval(position[i][0][0], position[i][0][1], position[i][1][0], position[i][1][1], fill=position[i][3])
  94.         center = (position[i][0][0] + position[i][2], position[i][0][1] + position[i][2])
  95.         w.create_text(center[0], center[1], text=position[i][4])

  96.     myline = [('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D'), ('C', 'E'), ('D', 'E')]

  97.     for each in myline:
  98.         w.create_line(connect(each))

  99.     the_label = Label(w, text='你想去哪儿?')
  100.     the_label_window = Canvas.create_window(w, 540, 10, anchor=E, window=the_label)
  101.     button_a = Button(w, text='家', command=go2('家'))
  102.     button_a_window = Canvas.create_window(w, 540, 35, anchor=E, window=button_a)
  103.     button_b = Button(w, text='鱼C公园', command=go2('鱼C公园'))
  104.     button_b_window = Canvas.create_window(w, 540, 60, anchor=E, wind3ow=button_b)
  105.     button_c = Button(w, text='食物超市1~6', command=go2('食物超市1~6'))
  106.     button_c_window = Canvas.create_window(w, 540, 85, anchor=E, window=button_c)
  107.     button_d = Button(w, text='武器超市1~6', command=go2('武器超市1~6'))
  108.     button_d_window = Canvas.create_window(w, 540, 110, anchor=E, window=button_d)
  109.     button_e = Button(w, text='LV1打工仔公司', command=go2('LV1打工仔公司'))
  110.     button_e_window = Canvas.create_window(w, 540, 135, anchor=E, window=button_e)

  111. label1 = Label(w, text='六六湖秘密探险 V2.0\nSixty-six Lake Secret Adventure')
  112. label1_window = Canvas.create_window(w, 275, 125, window=label1)
  113. label2 = Label(w, text='你要做什么?')
  114. label2_window = Canvas.create_window(w, 275, 150, window=label2)
  115. choose1 = Button(w, text='出发', command=go)
  116. choose1_window = Canvas.create_window(w, 275, 175, window=choose1)
  117. choose2 = Button(w, text='查看背包', command=callback)
  118. choose1_window = Canvas.create_window(w, 275, 200, window=choose2)

  119. mainloop()
复制代码
  1. Exception in Tkinter callback
  2. Traceback (most recent call last):
  3.   File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/tkinter/__init__.py", line 2043, in __call__
  4.     return self.func(*args)
  5.            ~~~~~~~~~^^^^^^^
  6.   File "/Users/zhangxiang/Documents/六六湖秘密探险2.x(最新).py", line 117, in go
  7.     button_b = Button(w, text='鱼C公园', command=go2('鱼C公园'))
  8.                                                  ~~~^^^^^^^^^^^
  9.   File "/Users/zhangxiang/Documents/六六湖秘密探险2.x(最新).py", line 49, in go2
  10.     Radiobutton(v, text=power[i], variable=v, value=i+1, indicatoron=False).pack(anchor=W)
  11.     ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12.   File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/tkinter/__init__.py", line 3585, in __init__
  13.     Widget.__init__(self, master, 'radiobutton', cnf, kw)
  14.     ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  15.   File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/tkinter/__init__.py", line 2718, in __init__
  16.     self._setup(master, cnf)
  17.     ~~~~~~~~~~~^^^^^^^^^^^^^
  18.   File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/tkinter/__init__.py", line 2687, in _setup
  19.     self.tk = master.tk
  20.               ^^^^^^^^^
  21. AttributeError: 'IntVar' object has no attribute 'tk'. Did you mean: '_tk'?
复制代码
最佳答案
2024-2-9 18:22:55
修正了你程序的部分问题,具体我懒得介绍了,自己看吧,求一个最佳答案。

  1. from tkinter import *
  2. from math import *
  3. from time import *

  4. food = ['LV4 苹果(48)', 'LV4 苹果(48)', 'LV4 苹果(48)']
  5. power = ['LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺']
  6. full = 500
  7. money = 666

  8. root = Tk()
  9. root.title('六六湖秘密探险 V2.0 Feb.6th 2024 -- 六六游戏城V8888.66.5.1.0.456.17.0a7')

  10. w = Canvas(root, width=550, height=350)
  11. w.pack()

  12. v = IntVar()
  13. v.set(1)

  14. now = '家'

  15. road = {'家':{'鱼C公园':[1, 2, 30], '食物超市1~6':[2, 4, 90]}, \
  16.         '鱼C公园':{'家':[1, 2, 30], '食物超市1~6':[2, 3, 48], '武器超市1~6':[1, 3, 36]}, \
  17.         '食物超市1~6':{'家':[2, 4, 90], '鱼C公园':[2, 3, 48], 'LV1打工仔公司':[3, 4, 100]}, \
  18.         '武器超市1~6':{'鱼C公园':[1, 3, 36], 'LV1打工仔公司':[6, 6, 54]}, \
  19.         'LV1打工仔公司':{'食物超市1~6':[3, 4, 100], '武器超市1~6':[6, 6, 54]}}

  20. def callback():
  21.     print('啊!我被调用了')

  22. def go2(button):
  23.     if button == now:
  24.         label3 = Label(w, text='你就在这儿')
  25.         label3_window = Canvas.create_window(w, 540, 200, window=label3)
  26.     else:
  27.         w.delete(ALL)
  28.         w.after(500)
  29.         label4 = Label(w, text='Loading... 口口20%')
  30.         label4_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
  31.         w.delete(ALL)
  32.         w.after(500)
  33.         label5 = Label(w, text='Loading... 口口口口40%')
  34.         label5_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
  35.         w.delete(ALL)
  36.         w.after(500)
  37.         label6 = Label(w, text='【777警报】怪兽来袭!')
  38.         label6_window = Canvas.create_window(w, 275, 340, window=label4)
  39.         lpower = len(power)
  40.         for i in range(lpower):
  41.             Radiobutton(w, text=power[i], variable=v, value=i+1, indicatoron=False).pack(anchor=W)

  42. position = {'A':((5, 5), (65, 65), 30, 'red', '家'), \
  43.             'B':((70, 70), (130, 130), 30, 'orange', '鱼C公\n园'), \
  44.             'C':((170, 70), (230, 130), 30, 'yellow', '食物超\n市1~6'), \
  45.             'D':((70, 170), (130, 230), 30, 'green', '武器超\n市1~6'), \
  46.             'E':((170, 270), (230, 330), 30, 'blue', 'LV1打\n工仔公\n司')}

  47. def connect(x):
  48.     a = position[x[0]]
  49.     b = position[x[1]]
  50.     a_center = ((a[0][0] + a[2]), (a[0][1] + a[2]))
  51.     b_center = ((b[0][0] + b[2]), (b[0][1] + b[2]))
  52.     if a_center[0] < b_center[0] and a_center[1] < b_center[1]:
  53.         #右下I
  54.         temp = (a_center[0], b_center[1])
  55.         s1 = b_center[0] - temp[0]
  56.         s2 = temp[1] - a_center[1]
  57.         diff1 = 30 * sin(atan(s1/s2))
  58.         diff2 = 30 * sin(atan(s2/s1))
  59.         return a_center[0] + diff1, a_center[1] + diff2, b_center[0] - diff1, b_center[1] - diff2
  60.     elif a_center[0] > b_center[0] and a_center[1] < b_center[1]:
  61.         #左下II
  62.         temp = (a_center[0], b_center[1])
  63.         s1 = temp[1] - b_center[1]
  64.         s2 = temp[0] - a_center[0]
  65.         diff1 = 30 * sin(atan(s1/s2))
  66.         diff2 = 30 * sin(atan(s2/s1))
  67.         return a_center[0] - diff1, a_center[1] + diff2, b_center[0] + diff1, b_center[1] - diff2
  68.     elif a_center[0] > b_center[0] and a_center[1] > b_center[1]:
  69.         #左上III
  70.         temp = (a_center[0], b_center[1])
  71.         s1 = temp[1] - b_center[1]
  72.         s2 = a_center[0] - temp[0]
  73.         diff1 = 30 * sin(atan(s1/s2))
  74.         diff2 = 30 * sin(atan(s2/s1))
  75.         return a_center[0] - diff1, a_center[1] - diff2, b_center[0] + diff1, b_center[1] + diff2
  76.     elif a_center[0] < b_center[0] and a_center[1] > b_center[1]:
  77.         #右上IV
  78.         temp = (a_center[0], b_center[1])
  79.         s1 = temp[1] - b_center[1]
  80.         s2 = temp[0] - a_center[0]
  81.         diff1 = 30 * sin(atan(s1/s2))
  82.         diff2 = 30 * sin(atan(s2/s1))
  83.         return a_center[0] + diff1, a_center[1] - diff2, b_center[0] - diff1, b_center[1] + diff2
  84.     elif a_center[1] == b_center[1]:
  85.         #同行
  86.         return a_center[0] + 30, a_center[1], b_center[0] - 30, b_center[1]
  87.     elif a_center[0] == b_center[0]:
  88.         #同列
  89.         return a_center[0], a_center[1] + 30, b_center[0], b_center[1] - 30

  90. def go():
  91.     w.delete(ALL)
  92.     for i in list(position.keys()):
  93.         w.create_oval(position[i][0][0], position[i][0][1], position[i][1][0], position[i][1][1], fill=position[i][3])
  94.         center = (position[i][0][0] + position[i][2], position[i][0][1] + position[i][2])
  95.         w.create_text(center[0], center[1], text=position[i][4])

  96.     myline = [('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D'), ('C', 'E'), ('D', 'E')]

  97.     for each in myline:
  98.         w.create_line(connect(each))

  99.     the_label = Label(w, text='你想去哪儿?')
  100.     the_label_window = Canvas.create_window(w, 540, 10, anchor=E, window=the_label)
  101.     button_a = Button(w, text='家', command=lambda:go2('家'))
  102.     button_a_window = Canvas.create_window(w, 540, 35, anchor=E, window=button_a)
  103.     button_b = Button(w, text='鱼C公园', command=lambda:go2('鱼C公园'))
  104.     button_b_window = Canvas.create_window(w, 540, 60, anchor=E, window=button_b)
  105.     button_c = Button(w, text='食物超市1~6', command=lambda:go2('食物超市1~6'))
  106.     button_c_window = Canvas.create_window(w, 540, 85, anchor=E, window=button_c)
  107.     button_d = Button(w, text='武器超市1~6', command=lambda:go2('武器超市1~6'))
  108.     button_d_window = Canvas.create_window(w, 540, 110, anchor=E, window=button_d)
  109.     button_e = Button(w, text='LV1打工仔公司', command=lambda:go2('LV1打工仔公司'))
  110.     button_e_window = Canvas.create_window(w, 540, 135, anchor=E, window=button_e)

  111. label1 = Label(w, text='六六湖秘密探险 V2.0\nSixty-six Lake Secret Adventure')
  112. label1_window = Canvas.create_window(w, 275, 125, window=label1)
  113. label2 = Label(w, text='你要做什么?')
  114. label2_window = Canvas.create_window(w, 275, 150, window=label2)
  115. choose1 = Button(w, text='出发', command=go)
  116. choose1_window = Canvas.create_window(w, 275, 175, window=choose1)
  117. choose2 = Button(w, text='查看背包', command=callback)
  118. choose1_window = Canvas.create_window(w, 275, 200, window=choose2)

  119. mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-2-9 17:43:15 | 显示全部楼层
你好,看起来你在编写一个使用Tkinter实现的游戏界面,但是代码中存在一些错误。以下是一些可能导致错误的地方:

1. 在创建按钮时,你给`command`参数传递了`go2('鱼C公园')`。然而,`command`参数需要的是一个函数名,而不是函数调用的结果。你可以将这个语句改为`command=lambda: go2('鱼C公园')`。

2. `Radiobutton`的第一个参数是父组件,但你传递的是一个`IntVar`对象。你应该将它改为传递`w`,即`Radiobutton(w, text=power, variable=v, value=i+1, indicatoron=False)`。

3. 在connect函数中,position[x]表示的是一个元组,你不能直接进行运算。你需要为元组中的每个元素进行运算。例如,`a_center = ((a[0] + a[2]) / 2, (a[1] + a[3]) / 2)`。

4. 在connect函数的最后,你返回的是四个坐标,但你没有将它们存储在变量中。你需要在函数的结尾添加一个返回语句,例如`return a_x, a_y, b_x, b_y`。

请尝试根据上述建议进行修改,并确保代码的其他部分也正确无误。如果还有其他问题,请随时向我提问。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-2-9 18:09:02 | 显示全部楼层
换用低版本python(3.9)及所对应的低版本tkinter试试看
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-2-9 18:12:19 | 显示全部楼层
tommyyu 发表于 2024-2-9 18:09
换用低版本python(3.9)及所对应的低版本tkinter试试看

怎么改啊?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-2-9 18:15:44 | 显示全部楼层

下载低版本的 python
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-2-9 18:19:10 | 显示全部楼层


刚刚我在我这里试了一下,3.8 运行你这个程序没有问题,应该是 3.13 的 bug 导致出现的问题。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-2-9 18:22:55 | 显示全部楼层    本楼为最佳答案   
修正了你程序的部分问题,具体我懒得介绍了,自己看吧,求一个最佳答案。

  1. from tkinter import *
  2. from math import *
  3. from time import *

  4. food = ['LV4 苹果(48)', 'LV4 苹果(48)', 'LV4 苹果(48)']
  5. power = ['LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺', 'LV3 三jio尺']
  6. full = 500
  7. money = 666

  8. root = Tk()
  9. root.title('六六湖秘密探险 V2.0 Feb.6th 2024 -- 六六游戏城V8888.66.5.1.0.456.17.0a7')

  10. w = Canvas(root, width=550, height=350)
  11. w.pack()

  12. v = IntVar()
  13. v.set(1)

  14. now = '家'

  15. road = {'家':{'鱼C公园':[1, 2, 30], '食物超市1~6':[2, 4, 90]}, \
  16.         '鱼C公园':{'家':[1, 2, 30], '食物超市1~6':[2, 3, 48], '武器超市1~6':[1, 3, 36]}, \
  17.         '食物超市1~6':{'家':[2, 4, 90], '鱼C公园':[2, 3, 48], 'LV1打工仔公司':[3, 4, 100]}, \
  18.         '武器超市1~6':{'鱼C公园':[1, 3, 36], 'LV1打工仔公司':[6, 6, 54]}, \
  19.         'LV1打工仔公司':{'食物超市1~6':[3, 4, 100], '武器超市1~6':[6, 6, 54]}}

  20. def callback():
  21.     print('啊!我被调用了')

  22. def go2(button):
  23.     if button == now:
  24.         label3 = Label(w, text='你就在这儿')
  25.         label3_window = Canvas.create_window(w, 540, 200, window=label3)
  26.     else:
  27.         w.delete(ALL)
  28.         w.after(500)
  29.         label4 = Label(w, text='Loading... 口口20%')
  30.         label4_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
  31.         w.delete(ALL)
  32.         w.after(500)
  33.         label5 = Label(w, text='Loading... 口口口口40%')
  34.         label5_window = Canvas.create_window(w, 275, 340, anchor=W, window=label4)
  35.         w.delete(ALL)
  36.         w.after(500)
  37.         label6 = Label(w, text='【777警报】怪兽来袭!')
  38.         label6_window = Canvas.create_window(w, 275, 340, window=label4)
  39.         lpower = len(power)
  40.         for i in range(lpower):
  41.             Radiobutton(w, text=power[i], variable=v, value=i+1, indicatoron=False).pack(anchor=W)

  42. position = {'A':((5, 5), (65, 65), 30, 'red', '家'), \
  43.             'B':((70, 70), (130, 130), 30, 'orange', '鱼C公\n园'), \
  44.             'C':((170, 70), (230, 130), 30, 'yellow', '食物超\n市1~6'), \
  45.             'D':((70, 170), (130, 230), 30, 'green', '武器超\n市1~6'), \
  46.             'E':((170, 270), (230, 330), 30, 'blue', 'LV1打\n工仔公\n司')}

  47. def connect(x):
  48.     a = position[x[0]]
  49.     b = position[x[1]]
  50.     a_center = ((a[0][0] + a[2]), (a[0][1] + a[2]))
  51.     b_center = ((b[0][0] + b[2]), (b[0][1] + b[2]))
  52.     if a_center[0] < b_center[0] and a_center[1] < b_center[1]:
  53.         #右下I
  54.         temp = (a_center[0], b_center[1])
  55.         s1 = b_center[0] - temp[0]
  56.         s2 = temp[1] - a_center[1]
  57.         diff1 = 30 * sin(atan(s1/s2))
  58.         diff2 = 30 * sin(atan(s2/s1))
  59.         return a_center[0] + diff1, a_center[1] + diff2, b_center[0] - diff1, b_center[1] - diff2
  60.     elif a_center[0] > b_center[0] and a_center[1] < b_center[1]:
  61.         #左下II
  62.         temp = (a_center[0], b_center[1])
  63.         s1 = temp[1] - b_center[1]
  64.         s2 = temp[0] - a_center[0]
  65.         diff1 = 30 * sin(atan(s1/s2))
  66.         diff2 = 30 * sin(atan(s2/s1))
  67.         return a_center[0] - diff1, a_center[1] + diff2, b_center[0] + diff1, b_center[1] - diff2
  68.     elif a_center[0] > b_center[0] and a_center[1] > b_center[1]:
  69.         #左上III
  70.         temp = (a_center[0], b_center[1])
  71.         s1 = temp[1] - b_center[1]
  72.         s2 = a_center[0] - temp[0]
  73.         diff1 = 30 * sin(atan(s1/s2))
  74.         diff2 = 30 * sin(atan(s2/s1))
  75.         return a_center[0] - diff1, a_center[1] - diff2, b_center[0] + diff1, b_center[1] + diff2
  76.     elif a_center[0] < b_center[0] and a_center[1] > b_center[1]:
  77.         #右上IV
  78.         temp = (a_center[0], b_center[1])
  79.         s1 = temp[1] - b_center[1]
  80.         s2 = temp[0] - a_center[0]
  81.         diff1 = 30 * sin(atan(s1/s2))
  82.         diff2 = 30 * sin(atan(s2/s1))
  83.         return a_center[0] + diff1, a_center[1] - diff2, b_center[0] - diff1, b_center[1] + diff2
  84.     elif a_center[1] == b_center[1]:
  85.         #同行
  86.         return a_center[0] + 30, a_center[1], b_center[0] - 30, b_center[1]
  87.     elif a_center[0] == b_center[0]:
  88.         #同列
  89.         return a_center[0], a_center[1] + 30, b_center[0], b_center[1] - 30

  90. def go():
  91.     w.delete(ALL)
  92.     for i in list(position.keys()):
  93.         w.create_oval(position[i][0][0], position[i][0][1], position[i][1][0], position[i][1][1], fill=position[i][3])
  94.         center = (position[i][0][0] + position[i][2], position[i][0][1] + position[i][2])
  95.         w.create_text(center[0], center[1], text=position[i][4])

  96.     myline = [('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D'), ('C', 'E'), ('D', 'E')]

  97.     for each in myline:
  98.         w.create_line(connect(each))

  99.     the_label = Label(w, text='你想去哪儿?')
  100.     the_label_window = Canvas.create_window(w, 540, 10, anchor=E, window=the_label)
  101.     button_a = Button(w, text='家', command=lambda:go2('家'))
  102.     button_a_window = Canvas.create_window(w, 540, 35, anchor=E, window=button_a)
  103.     button_b = Button(w, text='鱼C公园', command=lambda:go2('鱼C公园'))
  104.     button_b_window = Canvas.create_window(w, 540, 60, anchor=E, window=button_b)
  105.     button_c = Button(w, text='食物超市1~6', command=lambda:go2('食物超市1~6'))
  106.     button_c_window = Canvas.create_window(w, 540, 85, anchor=E, window=button_c)
  107.     button_d = Button(w, text='武器超市1~6', command=lambda:go2('武器超市1~6'))
  108.     button_d_window = Canvas.create_window(w, 540, 110, anchor=E, window=button_d)
  109.     button_e = Button(w, text='LV1打工仔公司', command=lambda:go2('LV1打工仔公司'))
  110.     button_e_window = Canvas.create_window(w, 540, 135, anchor=E, window=button_e)

  111. label1 = Label(w, text='六六湖秘密探险 V2.0\nSixty-six Lake Secret Adventure')
  112. label1_window = Canvas.create_window(w, 275, 125, window=label1)
  113. label2 = Label(w, text='你要做什么?')
  114. label2_window = Canvas.create_window(w, 275, 150, window=label2)
  115. choose1 = Button(w, text='出发', command=go)
  116. choose1_window = Canvas.create_window(w, 275, 175, window=choose1)
  117. choose2 = Button(w, text='查看背包', command=callback)
  118. choose1_window = Canvas.create_window(w, 275, 200, window=choose2)

  119. mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-2-9 19:03:45 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-23 17:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表