Home > other >  The problem of parameter passing python class method
The problem of parameter passing python class method

Time:09-16

Application reads the data from the excel file, set the output path, click a button on the bottom, can generate graphics,
The source data (similar to the following XLSX file) :


The code is as follows:
 import tkinter as tk 
The import tkinter. Filedialog as fd
The import plotly as py
The import plotly. Graph_objs as go
The import openpyxl
The import pandas as pd
The import OS


The class App (tk. Tk) :

Def __init__ (self) :
Super () __init__ ()
Btn_file=tk. The Button (self, text="Step1: Import data from", the command=self. Choose_file)
Btn_dir=tk. The Button (self, text="Step2: Set the output path",
The command=self. Choose_directory)
Btn_start=tk. The Button (self, text="Step3: Start to plot", the command=self. Start)
Btn_file. Pack (padx=60, pady=10)
Btn_dir. Pack (padx=60, pady=10)
Btn_start. Pack (padx=60, pady=10)

Def choose_file (self) :
Filetypes=((" Excel files ", "*. XLSX"),
)
Filename=fd. Askopenfilename (title="Open file",
Initialdir="/", filetypes=filetypes)
If filename:
Print (filename)

Def choose_directory (self) :
The directory=fd. Askdirectory (title="Open directory",
Initialdir="/")
If the directory:
Print (directory)

Def start (self, the filename, directory) :
The self. The filename=filename
The self. The directory=directory
Self. SP (filename, directory)


Def SP (self, input_file output_dir) :
The self. The input_file=input_file
Self. Output_dir=output_dir
Wb=openpyxl. Load_workbook (self. Input_file)
Sheet=wb/' Sheet1 '
Row_max=sheet. Max_row
Col_max=sheet. Max_column
First_row_list=[]
First_col_list=[]
, col_max for col_n in range (2 + 1) :
First_row_list. Append (sheet) cell (row=1, the column=col_n) value)
, row_max for row_n in range (2 + 1) :
First_col_list. Append (sheet) cell (row=row_n, column=1). The value)

Data_all=pd. Read_excel (self. Input_file)
Data_selected=data_all. Loc [: first_row_list]

Df=pd DataFrame (data_selected)
Df. Index=first_col_list
Colors=[' RGB (150204, living) ', 'RGB (255, 130, 71)', 'RGB (255, 193, 37)', 'RGB (180240190)', 'RGB (255, 10, 1),
'RGB (25, 19, 3)', 'RGB (100, 100, 100)', 'RGB (45,24,200)', 'RGB (33, 58, 108)', 'RGB (35, 208, 232)]

Data=https://bbs.csdn.net/topics/[go. Scatter (
X=df columns,
Y=[country] * len (df) columns),
Mode='markers + text,
Marker=dict (
Color=colors (num),
Size=df. Loc [country],
Showscale=False,
),
Text=list (map (STR, df. Loc [country])),
Textposition='middle center',
)
For num, the country in enumerate (reversed (df) index))
]

Layout=go. Layout (plot_bgcolor='RGB (10, 10, 10),
Paper_bgcolor='RGB (20, 55, 100),
The font={
'the size: 15,
'family' : 'sans-serif,
'color' : 'RGB (255, 255, 255)'
},
Width=1000,
Height=800,
Xaxis=dict (
Title='Output of grapes per year in the company countries',
Nticks=col_max + 1,
Type='category',
),
Showlegend=False,
Margin=dict (l=100 r=100, t=100, b=100),
Hovermode=False,
)

FIG.=go Figure (data=https://bbs.csdn.net/topics/data, layout=layout)
Py. Offline. The plot (FIG, filename=OS. Path. Join (self) output_dir, 'bubble_diagram. HTML))


If __name__=="__main__" :
App=app ()
App. Mainloop ()


After the operation, the front two BuZhengChang, click the last button, the system error:
TypeError: start () the missing 2 required positional arguments: 'filename' and 'the directory'
Could you tell me how to modify?

CodePudding user response:

The start method cannot have parameters, it is threads execute entry

CodePudding user response:

Found the problem: choose_file () and choose_directory () method in front of the filename and the directory attribute to add "self." can, perfect run!

CodePudding user response:

reference 1st floor tianfang response:
start method cannot have parameters, it is a thread of execution entry
yes, this place is one of the error,
  • Related