亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python:無法在多個文件中拆分文件

Python:無法在多個文件中拆分文件

開滿天機 2022-12-27 15:23:50
我有一個游戲項目,其中有我的服務器和客戶端。我想拆分我的客戶端和服務器,這樣更容易閱讀。我將所有配置 tkinter 窗口放在一個文件中,然后放入服務器from window import *。start_server()但是在 Windows 文件中,我正在調用客戶端中的一個函數,當我啟動客戶端時它無法識別該函數。有什么建議我該怎么做?謝謝你的幫助 !server.pyimport socketimport threadingfrom time import sleepfrom window import *def start_server():    global server, HOST_ADDR, HOST_PORT  # code is fine without this    btnStart.config(state=tk.DISABLED)    btnStop.config(state=tk.NORMAL)(...)window.pyimport tkinter as tkwindow = tk.Tk()window.title("Tic-Tac-Toe Server")window.iconbitmap("logo.ico")window.config(background='#4065A4')# Top frame consisting of two buttons widgets (i.e. btnStart, btnStop)topFrame = tk.Frame(window)btnStart = tk.Button(topFrame, text="Start", font=("Helvetica", 20), bg='#4065A4', fg='white',                     command=lambda : start_server())btnStart.pack(side=tk.LEFT)btnStop = tk.Button(topFrame, text="Stop", font=("Helvetica", 20), bg='#4065A4', fg='white', command=lambda : stop_server(), state=tk.DISABLED)btnStop.pack(side=tk.LEFT)topFrame.pack(side=tk.TOP, pady=(5, 0))# Middle frame consisting of two labels for displaying the host and port infomiddleFrame = tk.Frame(window)lblHost = tk.Label(middleFrame, font=("Helvetica", 10), bg='#4065A4', fg='white', text = "Address: X.X.X.X")lblHost.pack(side=tk.LEFT)lblPort = tk.Label(middleFrame, font=("Helvetica", 10), bg='#4065A4', fg='white', text = "Port:XXXX")lblPort.pack(side=tk.LEFT)middleFrame.pack(side=tk.TOP, pady=(5, 0))# The client frame shows the client areaclientFrame = tk.Frame(window)lblLine = tk.Label(clientFrame,  font=("Helvetica"), text="Liste des joueurs").pack()scrollBar = tk.Scrollbar(clientFrame)scrollBar.pack(side=tk.RIGHT, fill=tk.Y)tkDisplay = tk.Text(clientFrame, height=10, width=30)tkDisplay.pack(side=tk.LEFT, fill=tk.Y, padx=(5, 0))scrollBar.config(command=tkDisplay.yview)tkDisplay.config(yscrollcommand=scrollBar.set, background="#F4F6F7", highlightbackground="grey", state="disabled")clientFrame.pack(side=tk.BOTTOM, pady=(5, 10))
查看完整描述

1 回答

?
胡子哥哥

TA貢獻1825條經驗 獲得超6個贊

window導入后在 server.py 中綁定/配置回調。

window.py

...
btnStart = tk.Button(topFrame, text="Start", font=("Helvetica", 20), bg='#4065A4', fg='white')
...

server.py

...
from window import *
btnStart.configure(command=lambda : start_server())
...

設置選項


查看完整回答
反對 回復 2022-12-27
  • 1 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號