读fits的tkinter程序

import matplotlib.pyplot as plt
from astropy.io import fits
import os
import numpy as np
from scipy import stats
import tkinter as tk
from tkinter.ttk import Combobox,Button
class fitsGUI():
    def __init__(self):
        ################################################################################################################
        """设置主窗口,主场口大小为1000*1000"""
        self.root=tk.Tk()
        self.root.geometry('1000x1000')
        ################################################################################################################
        """设置第一个组合框,用来选择当前目录下的fits文件"""
        self.combobox1=Combobox(master=self.root,value=os.listdir(),state="readonly")
        self.combobox1.place(relx=0,rely=0,relheight=0.03,relwidth=0.2)
        self.combobox1.bind('<<ComboboxSelected>>',self.comboboxSelect1)
        ################################################################################################################
        """设置一个按钮,组合框3和4选择好数据之后按动按钮,开始以3的数据为x,4的数据为y绘制散点图"""
        self.plotButton=Button(master=self.root,text='StartPlot',command=self.plotButtonFunc)
        self.plotButton.place(relx=4/10,rely=1/10,relheight=0.5/10,relwidth=2/10)
        ################################################################################################################
        """主窗口运行"""
        self.root.mainloop()
        self.hdul.close()
    def comboboxSelect1(self,event):
        """第一个组合框对应的函数,用来显示选中的当前目录下的fits"""
        fitsName=self.combobox1.get()
        self.hdul=fits.open(fitsName)
        self.hdul.info()
        tableNum=len(self.hdul)
        self.tableList=[self.hdul[i].header['EXTNAME'] for i in range(1,tableNum)]
        ############################################################
        """设置第二个组合框,用来显示所选fits的所有Table"""
        # tableList=self.tableList
        # tableList.append("PRIMARY")
        self.combobox2=Combobox(master=self.root,value=self.tableList,state="readonly")
        self.combobox2.place(relx=0.3,rely=0,relheight=0.03,relwidth=0.2)
        self.combobox2.bind('<<ComboboxSelected>>',self.comboboxSelect2)
    def comboboxSelect2(self,event):
        """第二个组合框对应的函数,第二个组合框是用来选择当前hdul中的tableName的"""
        self.tableName=self.combobox2.get()
        fieldNameList=self.hdul[self.tableName].columns.names
        print(self.hdul[self.tableName].columns)
        ############################################################
        """设置第三个和第四个组合框,这两个组合框里面都是第二个选出的table中的filedName,然后分别选一个用来画散点图"""
        self.combobox3=Combobox(master=self.root,value=fieldNameList,state="readonly")
        self.combobox3.place(relx=0.6,rely=0,relheight=0.03,relwidth=0.12)
        self.combobox3.bind('<<ComboboxSelected>>',self.comboboxSelect3)
        self.combobox4=Combobox(master=self.root,value=fieldNameList,state="readonly")
        self.combobox4.place(relx=0.85,rely=0,relheight=0.03,relwidth=0.12)
        self.combobox4.bind('<<ComboboxSelected>>',self.comboboxSelect4)
    def comboboxSelect3(self,event):
        filedNameX=self.combobox3.get()
        self.xData=self.hdul[self.tableName].data[filedNameX]
    def comboboxSelect4(self,event):
        filedNameY = self.combobox4.get()
        self.yData=self.hdul[self.tableName].data[filedNameY]
    def plotButtonFunc(self):
        plt.close()
        fig=plt.figure(figsize=(10,10))
        ax=plt.axes((0.1,0.1,0.8,0.8))
        ax.scatter(self.xData,self.yData,s=2,c='black')
        plt.show()
if __name__=="__main__":
    fitsGUI()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值