Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to python and I need python combobox selection to show on an excel sheet('Header'), range('C25'). The code I am using is as follows. Any help will be highly appreciated

What I have tried:

Python
<pre><pre lang="Python">
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import showinfo
from calendar import month_name
import xlwings as xw

class ComboboxSelectionWindow():
    def __init__(self, master):
        self.master=master
        self.master.geometry('500x250')
        self.master.style= ttk.Style()
        self.master.style.theme_use('clam')
        self.master.style.configure("TCombobox", fieldbackground= "light blue", background= "white")
        
        self.entry_contents=None
        self.labelTop = tk.Label(master,text = "Porosity Scale Selection", background = 'blue', foreground ="white", font = ("Arial", 15))
        self.labelTop.place(x = 20, y = 10, width=240, height=30)
        self.comboBox_example = ttk.Combobox(master,values=["Limestone","Sandstone","Dolomite"])
        
        self.comboBox_example.current(0)
        self.comboBox_example.place(x = 20, y = 60, width=200, height=25)

        self.okButton = tk.Button(master, text='OK',command = self.callback)
        self.okButton.place(x = 20, y = 90, width=140, height=25)

    def callback(self):
        """ get the contents of the Entry and exit
        """
        self.comboBox_example_contents=self.comboBox_example.get()
        self.master.destroy()
        
def ComboboxSelection():

    app = tk.Tk()
    app.geometry('180x100')
    Selection=ComboboxSelectionWindow(app)
    app.mainloop()

    return Selection.comboBox_example_contents
    
wb = xw.books['1. Petrophysical Analysis.xlsx']
shth = wb.sheets['Header']
wb.sheets['Header'].select()
wb.sheets['Header'].cells(25, 3).Value = ComboboxSelection()
Posted
Comments
Richard MacCutchan 21-Jul-22 8:21am    
So what happens when you run the code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900