1
import tkinter
import csv
def mainapp():
print ('R')
def SigUP():
U = input1.get()
P = input2.get()
R = input3.get()
def P():
myData = [[U, P, R]]
myFile = open('csvexample3.csv', 'w')
with myFile:
writer = csv.writer(myFile)
writer.writerows(myData)
if U == '' or P == '' or R == '':
print ('No')
else:
P()
def LogIN():
U = input1.get()
P = input2.get()
R = input3.get()
main = tkinter.Tk()
realname = tkinter.Label(main, text='Real Name')
input3 = tkinter.Entry(main)
Username = tkinter.Label(main, text='Username')
input1 = tkinter.Entry(main)
Password = tkinter.Label(main, text='Password')
input2 = tkinter.Entry(main, show="*")
SigUp = tkinter.Button(main, text='Join Us Now', command=SigUP)
LogIn = tkinter.Button(main, text='Log In', command=LogIN)
input3.grid(column='2', row='1')
realname.grid(column='1', row='1')
input1.grid(column='2', row='2')
Username.grid(column='1', row='2')
input2.grid(column='2', row='3')
Password.grid(column='1', row='3')
SigUp.grid(columnspan='3', row='5')
LogIn.grid(columnspan='3', row='4')
main.mainloop()
在我的csv文件,我得到這個:
Ben4594,<function SigUP.<locals>.P at 0x101d51950>,Ben
我希望我的CSV應該是這樣的:
Ben4594,Password,Ben
我使用python 3和tkinter。
你能格式化你的代碼嗎?這一個不是很好。 – PerunSS
借調,代碼沒有正確縮進。嘗試用四個空格縮進整個代碼,然後將其粘貼回問題中。 – mjsqu
看起來,在寫入csv的地方,你正在寫'P',它實際上是引用函數'P()',而不是你之前分配給變量'P'的輸入。使用適當的變量和函數名可以避免這個問題。 –